Я использовал этот метод PHP, чтобы получить информацию, если продукты из корзины только из «класса судоходства в классе My-Custom». нравится показывать все мотоды, кроме «судоходного метода-1». < /p>
Код: Выделить всё
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]