如何在woocommerce中设置最小订单重量? [英] How to set minimum weight of order in woocommerce?

查看:28
本文介绍了如何在woocommerce中设置最小订单重量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 WordPress 中获取 Woo Commerce 产品变化值.我有 250g、500g 和 1kg 三个值.我限制了结帐流程 500g.

解决方案

将此代码添加到 functions.php.您可以在

How to get Woo Commerce product variation values in WordPress .I've three values 250g,500g and 1kg. I've restrict on checkout process 500g.

解决方案

Add this code to functions.php. You may check article here

 add_action( 'woocommerce_check_cart_items', 'cldws_set_weight_requirements' );
    function cldws_set_weight_requirements() {
     // Only run in the Cart or Checkout pages
     if( is_cart() || is_checkout() ) {
     global $woocommerce;
     // Set the minimum weight before checking out
     $minimum_weight = 500;
     // Get the Cart's content total weight
     $cart_contents_weight = WC()->cart->cart_contents_weight;
     // Compare values and add an error is Cart's total weight
     if( $cart_contents_weight < $minimum_weight  ) {
     // Display our error message
     wc_add_notice( sprintf('<strong>A Minimum Weight of %s%s is required before checking out.</strong>'
     . '<br />Current cart weight: %s%s',
     $minimum_weight,
     get_option( 'woocommerce_weight_unit' ),
     $cart_contents_weight,
     get_option( 'woocommerce_weight_unit' ),
     get_permalink( wc_get_page_id( 'shop' ) )
     ),
     'error' );
     }
     }
    }

这篇关于如何在woocommerce中设置最小订单重量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆