Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 如何在woocommerce中设置订单的最小权重?_Wordpress - Fatal编程技术网

Wordpress 如何在woocommerce中设置订单的最小权重?

Wordpress 如何在woocommerce中设置订单的最小权重?,wordpress,Wordpress,如何在WordPress中获得Woo Commerce产品的变化值。我有三个值250g、500g和1kg。 我限制了500克的结帐过程 将此代码添加到functions.php。你可以查这篇文章 add_action('woocommerce_check_cart_items'、'cldws_set_weight_requirements'); 功能cldws\u设置\u重量\u要求(){ //仅在购物车或结帐页面中运行 if(is_cart()| | is_checkout()){ 全球商业;

如何在WordPress中获得Woo Commerce产品的变化值。我有三个值250g、500g和1kg。
我限制了500克的结帐过程

将此代码添加到functions.php。你可以查这篇文章

add_action('woocommerce_check_cart_items'、'cldws_set_weight_requirements');
功能cldws\u设置\u重量\u要求(){
//仅在购物车或结帐页面中运行
if(is_cart()| | is_checkout()){
全球商业;
//退房前设置最小重量
$最小重量=500;
//获取购物车的内容总重量
$cart\u contents\u weight=WC()->cart->cart\u contents\u weight;
//比较值并添加一个错误是购物车的总重量
如果($cart\u contents\u weight<$minimum\u weight){
//显示我们的错误消息
wc_添加通知(sprintf(“退房前要求最小重量为%s%s)。”
“
当前购物车重量:%s%s”, $最小重量, 获取选项(“重量单位”), $cart\u内容物\u重量, 获取选项(“重量单位”), 获取永久链接(wc获取页面id('shop')) ), “错误”); } } }

我可以在哪里将此代码添加到文件中?您可以这样实现。或提供完整的细节,你想如何使用。显示位置我想在用户结账时添加结账过程,它将生成一条消息,最小重量值购买500g而不是250g。当用户购买500g或更多时,将显示结账按钮。我仍然无法获得可变产品属性值。当我使用上面的代码时,没有显示任何内容,其显示为空?确定,获得它。给我几分钟这是一份
 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' );
     }
     }
    }