WooCommerce(多重货币)的最低订单

发布于 2025-01-23 03:44:43 字数 965 浏览 0 评论 0原文

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

this code works for everything, I want to specify it to certain currency
for example, 14$ is the minimum order in USD, but when currency converters to AED it stays 14 it should be 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'
            );
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷遇一生 2025-01-30 03:44:43

您可以定义最小变量如下:

  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'
              );
          }
      }
  }

对其进行测试和工作

you can define the minium variable as following:

  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'
              );
          }
      }
  }

tested it and working

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文