脚本宝典收集整理的这篇文章主要介绍了php – 以编程方式为Woocommerce 3添加有条件的折扣,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我只找到了附加优惠券或以编程方式创建优惠券的解决方案.我在结账时没有发现临时优惠券.
同样重要的是,这张优惠券可以与其他优惠券相结合,而不是更多.
这是我的代码:
if ( get_discount_points() < 100 ) { //Customer has bonus status 1 } elseif ( get_discount_points() < 200 ) { //Customer has bonus status 2 } else { //Customer has bonus status x
按折扣百分比计算
}
这甚至可能吗?
function get_customer_discount(){ if( $points = get_discount_points() ){ if ( $points < 100 ) { return 1; // 1 % discount } elseif ( $points < 200 ) { return 2; // 2.5 % discount } else { return 4; // 5 % discount } } else { return false; } } add_action( 'woocommerce_cart_calculate_fees','custom_discount',10,1 ); function custom_discount( $cart ){ if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; // Only for 2 ITems or more if( $PErcentage = get_customer_discount() ){ $discount = WC()->cart->get_subtotal() * $percentage / 100; // Apply discount to 2nd item for non on sale items in cart if( $discount > 0 ) $cart->add_fee( sPRintf( __("Discount %s%%"),$percentage),-$discount ); } }
以上是脚本宝典为你收集整理的php – 以编程方式为Woocommerce 3添加有条件的折扣全部内容,希望文章能够帮你解决php – 以编程方式为Woocommerce 3添加有条件的折扣所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。