woocommerce 배송 옵션에 도움이 필요합니다. 지역 배송 또는 현지 픽업 옵션 만 보여주고 싶은 특정 제품 카테고리의 고정 요금을 숨기려고합니다.배송 제거 WooCommerce 2.6 및 3+의 특정 카테고리에 대한 정액 요금제
다른 모든 카테고리의 경우 모든 옵션이 작동합니다.
나는 (내 테마의 function.php 파일에 추가) 그 코드로 수행하려고 있습니다
function cart_has_product_with_orange_cats() {
global $woocommerce;
$product_in_cart = false;
// start of the loop that fetches the cart items
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
$terms = get_the_terms($_product->id, 'product_cat');
// second level loop search, in case some items have several categories
if($terms){
foreach ($terms as $term) {
$_categoryid = $term->term_id;
if ($_categoryid == 16) {
//category is in cart!
$product_in_cart = true;
}
}
}
}
return $product_in_cart;
}
// add filter and function to hide method
add_filter('woocommerce_available_shipping_methods', 'custom_shipping_methods' , 10, 1);
function custom_shipping_methods($available_methods){
if (cart_has_product_with_orange_cats()) {
foreach($available_methods as $key => $method){
if($key == 'local_delivery' || $key == 'local_pickup'){
continue;
}
unset($available_methods[$key]);
}
// remove the rate you want
}
// return the available methods without the one you unset.
return $available_methods;
}
그러나 그것은 나를 위해 일하고, 어쩌면 때문에 최신 WooCommerce 버전의 오래된 코드 또는하지 않습니다 다른 문제.
어떻게하면됩니까?
감사합니다.
안녕, 당신의 멋진 대답, 그 작업에 대한 감사하지만, 단 하나의 문제는, 현지 픽업 옵션을 사용할 수 없습니다. 로컬 배달 만 표시합니다. 나는 로컬 픽업을 보여주고 싶다. 고맙습니다. –