Woocommerce的最低订单(多种货币)

时间:2018-04-12 12:52:39

标签: php wordpress woocommerce currency

此代码适用于所有内容,我想将其指定为特定货币 例如,14$USD中的最低订单,但当货币转换为AED它保持为14时,它应为51.52 AED

function wc_minimum_order_amount() {
    // Set this variable to specify a minimum order value
    $minimum = 14;

    if ( WC()->cart->total < $minimum ) {
        if( is_cart() ) {
            wc_print_notice(
                sprintf( 'You must have an order with a minimum of 52.5 AED Or 14 $ to place your order' ,
                    wc_price( $minimum ),
                    wc_price( WC()->cart->total )
                ), 'error'
            );
        } else {
            wc_add_notice(
                sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
                    wc_price( $minimum ),
                    wc_price( WC()->cart->total )
                ), 'error'
            );
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您可以将minium变量定义如下:

  add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
  add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
   function wc_minimum_order_amount() {
      // Set this variable to specify a minimum order value

  $currency = get_woocommerce_currency();

  if ($currency == 'USD'){
      $minimum = 14;
  }else{
    $minimum =51.52;
  }


      if ( WC()->cart->total < $minimum ) {
          if( is_cart() ) {
              wc_print_notice(
                  sprintf( 'You must have an order with a minimum of 52.5 AED Or 14 $ to place your order' ,
                      wc_price( $minimum ),
                      wc_price( WC()->cart->total )
                  ), 'error'
              );
          } else {
              wc_add_notice(
                  sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
                      wc_price( $minimum ),
                      wc_price( WC()->cart->total )
                  ), 'error'
              );
          }
      }
  }

测试并正常工作