【问题标题】:Minimum order on Woocommerce (multiple currency)Woocommerce 的最低订单(多种货币)
【发布时间】:2018-04-12 12:52:39
【问题描述】:

此代码适用于所有内容,我想将其指定为特定货币 例如,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'
            );
        }
    }
}

【问题讨论】:

  • 默认情况下 WooCommerce 不支持多币种。你用的是哪个多币种插件?

标签: php wordpress woocommerce currency


【解决方案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'
              );
          }
      }
  }

测试并运行

【讨论】:

  • 谢谢老兄,它有效
猜你喜欢
  • 2020-11-26
  • 1970-01-01
  • 1970-01-01
  • 2021-03-31
  • 1970-01-01
  • 2014-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多