Php 基于Woocommerce 3中的Shipping类筛选Shipping方法
我一直在搜索代码,以便在购物车(除其他产品外)中选择了特定装运类别(仅收货,ex.)的产品时,在结帐时过滤掉本地提货以外的任何装运方法Php 基于Woocommerce 3中的Shipping类筛选Shipping方法,php,wordpress,woocommerce,shipping,custom-taxonomy,Php,Wordpress,Woocommerce,Shipping,Custom Taxonomy,我一直在搜索代码,以便在购物车(除其他产品外)中选择了特定装运类别(仅收货,ex.)的产品时,在结帐时过滤掉本地提货以外的任何装运方法 我只找到过时的代码,在WC3+上不起作用。以下是在启用特定装运类别的产品时过滤掉除本地提货以外的任何装运方法的方法: add_filter( 'woocommerce_package_rates', 'custom_shipping_rates', 100, 2 ); function custom_shipping_rates( $rates, $packag
我只找到过时的代码,在WC3+上不起作用。以下是在启用特定装运类别的产品时过滤掉除本地提货以外的任何装运方法的方法:
add_filter( 'woocommerce_package_rates', 'custom_shipping_rates', 100, 2 );
function custom_shipping_rates( $rates, $package ) {
$shipping_class = 64; // HERE set the shipping class ID
$found = false;
// Loop through cart items Checking for the defined shipping method
foreach( $package['contents'] as $cart_item ) {
if ( $cart_item['data']->get_shipping_class_id() == $shipping_class ){
$found = true;
break;
}
}
if ( ! $found ) return $rates; // If not found we exit
// Loop through shipping methods
foreach( $rates as $rate_key => $rate ) {
// all other shipping methods other than "Local Pickup"
if ( 'local_pickup' !== $rate->method_id && $found ){
// Your code here
}
}
return $rates;
}
代码进入活动子主题(或活动主题)的function.php文件。测试和工作
然后在StackOverFlow中将允许您完成代码
您应该在问题中包含您尝试过的过时代码。谢谢!我将在哪个表中找到装运类别ID?