【发布时间】:2019-05-19 09:30:51
【问题描述】:
我有一个类别门,用于显示虚拟产品的运费。基本上我有一些我不想收取运费的产品,我把它们归为一个叫做礼物的类别……但我仍然想要一个送货地址。问题是,当我使用我构建的类别过滤器时,它不会按顺序保存地址......如果我只是使用......
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true', 50 );
效果很好……
但是当我把门放在上面时...它不会保存值...这里是门...
//gifts filter
function HDM_gift_shipping() {
// set our flag to be false until we find a product in that category
$cat_check = false;
// check each cart item for our category
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
// if cat matches gift return true
if ( has_term( 'gift', 'product_cat', $product->id ) ) {
$cat_check = true;
// break because we only need one "true" to matter here
break;
}
}
// if a product in the cart is in our category, do something
if ( $cat_check ) {
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true', 50 );
}
}
add_action('woocommerce_before_checkout_billing_form', 'HDM_gift_shipping', 100);
【问题讨论】:
标签: php wordpress woocommerce field checkout