本文介绍了如果WooCommerce购物车项目有待补货,请不要使用优惠券的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,这就是我所拥有的:
So far this is what I've got:
c>(错误的变量名称应为 $ valid )和一个扩展名 } ,因为您已注释了if语句,导致错误。There is a typo error in your code for $vaild = false; (wrong variable name should be $valid) and an exta } as you have commented an if statement, causing the error.
下面,我将您的代码升级到了更实际的版本(替换了 global $ woocommerce 和<$ c由 WC()-> cart 的$ c> $ woocommerce-> cart ):
Also below, I have upgraded your code to a more actual version (replacing global $woocommerce and $woocommerce->cart by WC()->cart):
add_filter( 'woocommerce_coupon_is_valid', 'coupon_always_valid', 99, 2 ); function coupon_always_valid( $valid, $coupon ){ $valid = true; foreach ( WC()->cart->get_cart() as $cart_item ) { // if($values['data']->backorders_allowed()){ //check if backorders are allowed on this product // get the stock quantity - returns the available amount number $stock_info = $cart_item['data']->get_stock_quantity(); if( $stock_info < 1 ){ $valid = false; ## <== HERE a typo error break; } // } ## <== HERE commented } return $valid ; }代码包含在您活动的子主题的function.php文件中(
现在此代码应该可以正常运行
这篇关于如果WooCommerce购物车项目有待补货,请不要使用优惠券的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!