【发布时间】:2021-10-28 23:20:24
【问题描述】:
我正在使用Disable free shipping for specific coupon codes in WooCommerce 答案代码
我想定位优惠券类型而不是特定代码。我该怎么办?我想将 'smart_coupons' 定位为类型。
更新 - 这是我想出的,虽然加载需要相当长的时间。它可能只是我的 WP,因为我有很多优惠券。有什么方法可以在结帐时只调用输入的优惠券而不是所有优惠券?
add_filter( 'woocommerce_package_rates', 'hide_free_shipping_method_based_on_coupons', 10, 2 );
function hide_free_shipping_method_based_on_coupons( $rates, $package )
{
$coupons = WC()->cart->get_coupons();
$applied_coupons = WC()->cart->get_applied_coupons(); // Applied coupons
foreach($coupons as $coupon_code) {
$coupon = new WC_Coupon( $coupon_code );
echo $coupon->get_discount_type();
}
if($coupon->get_discount_type() === 'smart_coupon') {
foreach ( $rates as $rate_key => $rate ) {
// Targetting "Free shipping"
if ( 'free_shipping' === $rate->method_id ) {
unset($rates[$rate_key]); // hide free shipping method
}
}
}
return $rates;
}
【问题讨论】:
-
你能指定优惠券类型或折扣类型吗?
-
请注意这不是代码编写或辅导服务。我们可以帮助解决具体的技术问题,而不是对代码或建议的开放式请求。请编辑您的问题以显示what you have tried so far to solve your problem,以及您需要帮助的具体问题。请参阅How to Ask 页面,详细了解如何最好地帮助我们。
-
折扣类型是'smart_coupons'
标签: php wordpress woocommerce coupon shipping-method