< /ol>
Я попытался достичь его, используя jquery, в пользовательском сценарии темы, но кажется, что сценарии jQuery не применяются к WP-блокам. 'My-Custom-Class Class' класс доставки.
Если ответ правда, то я хотел бы показать только один конкретный метод доставки (скажем, «судоходство-метод-1») и скрыть другие.
Если ответ неверно, я хотел бы показать все мотоды, кроме «судоходство-method-1».
Код: Выделить всё
function show_shipping_method() {
$slug = 'my-custom-shipping-class';
global $woocommerce;
$product_in_cart = false;
$other_product_in_cart = false;
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
$terms = get_the_terms($_product->id, 'product_shipping_class');
if ($terms) {
foreach ($terms as $term) {
$_shippingclass = $term->slug;
if ($slug === $_shippingclass) {
$product_in_cart = true;
} else {
$other_product_in_cart = true;
}
}
} else {
$other_product_in_cart = true;
}
}
return ($product_in_cart && !$other_product_in_cart);
}
< /code>
Затем в теме html я бы добавил пользовательский класс: < /p>
Подробнее здесь: [url]https://stackoverflow.com/questions/79550636/how-to-show-specific-shipping-method-only-for-certain-shipping-class[/url]
Мобильная версия