这种情况可能与FedEx WooCommerce Shipping with Print Label. 您只需要以下免费附加组件和下面的代码。
隐藏基于装运类别和区域的WooCommerce装运方法跳过基于WooCommerce装运类别的装运计算,以及这些免费插件,下面的文档中已经很好地解释了类似的情况-WooCommerce Shipping – FedEx Live Rate Adjustment based on Shipping Classes.
下面是需要添加到函数中的代码。php文件。。。
/**
* Snippet to Add an Additional Cost to the Shipping Service based on Shipping Class
* Created on 28 March 2019
* PluginHive Plugins: https://www.pluginhive.com/plugins/
**/
add_filter( \'woocommerce_package_rates\', \'adjustment_in_rates_of_product_with_shipping_class\', 12, 2 );
function adjustment_in_rates_of_product_with_shipping_class( $available_shipping_methods, $package ) {
// Shipping class slug that need to add extra cost
$shipping_class = array(
\'other\',
);
// Give here Extra Cost you want add
$extra_cost = 100;
// Enter the Shipping Method Value
$shipping_services = array(
\'wf_shipping_ups:01\',
\'wf_shipping_ups:02\',
\'wf_shipping_ups:03\',
\'wf_shipping_ups:07\',
\'wf_shipping_ups:08\',
\'wf_shipping_ups:11\',
\'wf_shipping_ups:12\',
\'wf_shipping_ups:13\',
\'wf_shipping_ups:14\',
\'wf_shipping_ups:59\',
\'wf_shipping_ups:54\',
\'wf_shipping_ups:65\',
\'wf_shipping_ups:92\',
\'wf_shipping_ups:93\',
\'wf_shipping_ups:94\',
);
$shipping_class_exists = false;
foreach(WC()->cart->get_cart_contents() as $key => $values) {
if ( in_array($values[\'data\']->get_shipping_class() , $shipping_class) ) {
$shipping_class_exists = true;
break;
}
}
if ($shipping_class_exists) {
foreach ($available_shipping_methods as $key => $value) {
if ( in_array($value->get_id() , $shipping_services) ) {
$available_shipping_methods[$key]->cost += $extra_cost;
}
}
}
return $available_shipping_methods;
}
如果您还有任何疑问,可以留下评论。