Так что я пытаюсь скрыть определенные методы корабля в Woocommerce на основе тега продукта. Основная проблема, я лицо мое отсутствия PHP знаний, поэтому я frankensteined следующего кода вместе с помощью некоторых очень дружелюбных людей:Скрыть параметры доставки Woocommerce
add_filter('woocommerce_available_shipping_methods', 'hide_shipping_based_on_tag' , 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) {
if (isset($array_item['product_tag']) && $array_item['product_tag'] == "CHOSEN_TAG") { // Replace "CHOSEN_TAG" with what ever tag you want
$found = true;
break;
}
}
return $found;
}
function hide_shipping_based_on_tag($available_methods) {
// use the function abve to check the cart for the tag.
if (check_cart_for_share()) {
// remove the rate you want
unset($available_methods['flat_rate']); // Replace "flar_rate" with the shipping option that yu want to remove.
}
// return the available methods without the one you unset.
return $available_methods;
}
Я понимаю, что этот код не является ни в коей мере не универсальная и, таким образом, переменные будет отличается от случая к случаю, но, возможно, кто-то может сказать мне, если что-то в коде. Большое спасибо
Этот код не работает? Или вы ищете больше того, как лучше ответить? Если это так, то этот вопрос лучше в http://codereview.stackexchange.com/. –