배송 클래스에 따라 배송 방법을 하나만 숨기려고합니다. 특정 클래스에 속한 제품을 선택했을 때 FedEx 야간 방법을 필수적으로 강요합니다.Woocommerce, 배송 클래스에 따른 배송 방법 숨기기
add_filter('woocommerce_available_shipping_methods', 'hide_shipping_based_on_class' , 10, 1);
function check_cart_for_share() {
// load the contents of the cart into an array.
global $woocommerce;
$cart = $woocommerce->cart->cart_contents;
$found = false;
// loop through the array looking for the tag you set. Switch to true if the tag is found.
foreach ($cart as $array_item) {
$term_list = wp_get_post_terms($array_item['product_id'], 'product_shipping_class', array("fields" => "names"));
if (in_array("Frozen",$term_list)) {
$found = true;
break;
}
}
return $found;
}
function hide_shipping_based_on_class($available_methods) {
// use the function above to check the cart for the tag.
if (check_cart_for_share()) {
// remove the rate you want
unset($available_methods['canada_post,purolator,fedex:FEDEX_GROUND,fedex:GOUND_HOME_DELIVERY']);
}
// return the available methods without the one you unset.
return $available_methods;
}
그것은 비록 어떤 배송 방법을 숨기는 것 같지 않습니다 아래에 표시된대로
나는 this code로 시작하고, 수정하고 있습니다. 아니 ... 확실히 내가 무엇을 누락
그것의 멀티 사이트 설치, 나는뿐만 아니라, 나는 테이블 비율 운송 모듈을 실행하는거야 http://stjeans.harbourcitydevelopment.com에서 캐나다 측에서 테스트하고 있습니다 FedEx, Purolator 및 캐나다 포스트 모듈.