-1
我想在Woocommerce中找到一种方式,让前100名顾客免费送货作为促销活动。免费送货给Woocommerce的100个第一客户
一旦达到100个第一客户的限制,则将应用标准装运。
这可能吗?我怎样才能做到这一点?
我想在Woocommerce中找到一种方式,让前100名顾客免费送货作为促销活动。免费送货给Woocommerce的100个第一客户
一旦达到100个第一客户的限制,则将应用标准装运。
这可能吗?我怎样才能做到这一点?
下面是一个简单的下面将在2上钩功能做这个工作的方式:
但你必须:
下面是代码:
// Auto apply "free_shipping" coupon for first hundred
add_action('woocommerce_before_calculate_totals', 'auto_apply_free_shipping_coupon_first_hundred', 10, 1);
function auto_apply_free_shipping_coupon_first_hundred($cart_object) {
// HERE define your free shipping coupon code
$coupon_code = 'summer';// 'freeship100';
if (is_admin() && ! defined('DOING_AJAX'))
return;
// Get an instance of the WC_Coupon object
$coupon_obj = new WC_Coupon($coupon_code);
// After 100 usages exit
if($coupon_obj->get_usage_count() > 100) return;
// Auto-apply "free shipping" coupon code
if (! $cart_object->has_discount($coupon_code) && is_cart()){
$cart_object->add_discount($coupon_code);
wc_clear_notices();
wc_add_notice(__('You have win Free shipping for the first 100 customers'), 'notice');
}
}
// Hide Others Shipping methods when "Free shipping is available
add_filter('woocommerce_package_rates', 'hide_others_when_free_shipping_is_available', 100);
function hide_others_when_free_shipping_is_available($rates) {
$free = array();
foreach ($rates as $rate_id => $rate) {
if ('free_shipping' === $rate->method_id) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty($free) ? $free : $rates;
}
代码放在您的活动子主题(或主题)的function.php文件或也以任何插件文件。
此代码已经过测试,适用于WooCommerce版本3+