【发布时间】:2018-05-28 20:35:20
【问题描述】:
我的购物车最低订单为 15 美元。但是,我想创建一些可以绕过最低订单要求的优惠券代码。我下面的代码允许我命名一个特定的优惠券。如何使用通配符,这样我就不必列出所有以字母 nm 开头的优惠券代码?
这是我正在使用的代码:
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
/* add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' ); */
add_action( 'woocommerce_check_cart_items' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 15;
// No minimum purchase if a specific coupon code is used
if ( WC()->cart->has_discount ( '*nm*' ) ) {
return;
}
if ( WC()->cart->subtotal < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order subtotal is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
}
}
}
我想使用通配符的代码在这里(上面代码中的第 3 段):
// No minimum purchase if a specific coupon code is used
if ( WC()->cart->has_discount ( 'nm*' ) ) {
return;
}
* 不起作用。我该如何编码?谢谢!!!!!!
【问题讨论】:
标签: woocommerce minimum coupon