我网站中的产品由 2 个运输插件之一处理: WooCommerce 的Printful Integration和WooCommerce Shipping 的 Printify。当每个运输插件有混合项目时。当有混合项目(这是一个冲突和一个问题)时,这些插件将每个运输包分成两部分。
因此,我在Printful 插件处理的产品中添加了一个运输类(id 是),并尝试通过@LoicTheAzec(欢呼)调整woocommerce 应答代码中特定运输类的隐藏运输方法,仅删除运输由于运输插件之间的冲突,来自具有 id 2 和 3 的特定重复运输包裹的方法...</p>
'printful'
548
这是我的实际代码:
add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_shipping_class', 10, 2 );
function hide_shipping_method_based_on_shipping_class( $rates, $package )
{
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// HERE define your shipping class to find
$class = 548; //CAMDEN HARBOR CHART MUG is in shipping class
// HERE define the shipping methods you want to hide
$method_key_ids = array('printify_shipping_s', 'printify_shipping_e');
// Checking in cart items
foreach( WC()->cart->get_cart() as $cart_item ){
// If we find the shipping class
if( $cart_item['data']->get_shipping_class_id() == $class ){
foreach( $method_key_ids as $method_key_id ){
unset($rates[$method_key_id]); // Remove the targeted methods
}
break; // Stop the loop
}
}
return $rates;
}
但它不起作用,我仍然得到 4 个运输包裹而不是两个:
任何帮助表示赞赏。