我有两个独立的产品; 1 件产品可作为优惠券,可通过邮寄/自提方式投递,1 件产品可发货。
如果我的购物车上有这两种商品,那么它们的两种运输选项都会显示。我只想能够显示 1 个产品的运输选项。
我尝试过使用不同的插件,即。 Woocommerce 有条件配送、Woocommerce 有条件配送和付款、Woocommerce 高级统一费率配送。
我没有尝试使用 php 代码来执行此操作,因为我没有编码经验,并且尽可能在仪表板上执行此操作。
我尝试对插件进行条件操作,以不显示产品的运输选项,但它始终显示产品的两个运输选项。
我从@businessbloomer 那里学到了这一点! 第一部分是一个函数,您可以将其保留在函数中。 第二部分检查购物车中的特定类别,您可以根据该猫是否在购物车中来取消设置运输方式
// check for shipping class in cart
function cart_has_product_with_shipping_class($slug)
{
global $woocommerce;
$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;
}
}
}
}
return $product_in_cart;
}
// remove all but desired for selected_category products
add_filter('woocommerce_package_rates', 'hide_all_but_desired_if_selected_category', 99);
function hide_all_but_desired_if_selected_category($rates)
{
$categories = array('selected-category-slug');
//if selected_category is in the cart
if (woo_custom_category_is_in_the_cart($categories)) {
unset($rates['table_rate:24:2']); // zone 1
unset($rates['table_rate:22']); // zone 2
}
return $rates;
}
您可以通过检查您的购物车运输方式来获得这些价格
你的案子解决了吗? 我有完全相同的问题,非常需要解决,请帮助我