回答
这个自定义代码将保持免费送货方法,并隐藏其他的运输方式时,车量最多为,如果产品不重(小于超过20公斤这里)...要不允许订单少于250免费送货,您可以在woocommerce (请参见最后)中进行设置。
首先,你必须确保重量在每个重产品设置的(简单或变量产品(每个变化)。推车大部这里是不含税(你可以把它改成包括。易税)
那么这里就是在woocommerce_package_rates
过滤钩子钩住定制功能:
add_filter('woocommerce_package_rates', 'conditionally_hide_other_shipping_based_on_items_weight', 100, 1);
function conditionally_hide_other_shipping_based_on_items_weight($rates) {
// Set HERE your targeted weight (here is 20 kg) <== <== <== <== <==
$target_product_weight = 20;
// Set HERE your targeted cart amount (here is 250) <== <== <== <== <==
$target_cart_amount = 250;
// For cart subtotal amount EXCLUDING TAXES
WC()->cart->subtotal_ex_tax >= $target_cart_amount ? $passed = true : $passed = false ;
// For cart subtotal amount INCLUDING TAXES (replace by this):
// WC()->cart->subtotal >= $target_cart_amount ? $passed = true : $passed = false ;
// Iterating trough cart items to get the weight for each item
foreach(WC()->cart->get_cart() as $cart_item){
if($cart_item['variation_id'] > 0)
$item_id = $cart_item['variation_id'];
else
$item_id = $cart_item['product_id'];
// Getting the product weight
$product_weight = get_post_meta($item_id , '_weight', true);
if(!empty($product_weight) && $product_weight >= $target_cart_amount){
$light_products_only = false;
break;
}
else $light_products_only = true;
}
// If 'free_shipping' method is available and if products are not heavy
// and cart amout up to the target limit, we hide other methods
$free = array();
foreach ($rates as $rate_id => $rate) {
if ('free_shipping' === $rate->method_id && $passed && $light_products_only) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty($free) ? $free : $rates;
}
代码会出现在您的活动子主题(或主题)的function.php文件中,或者也存在于任何插件文件中。
此代码测试,它适用于简单和变型产品...
你也将在WooCommerce设置>航运,每个出货区,为
"Free Shipping"
方法的最低订货量:
您需要刷新运输缓存数据:在woocommerce运输设置中禁用,保存并启用,保存当前运输区域的相关运输方式。
对于超过一定数量的免费送货,您可以使用内置的WooCommerce选项。
对于某些特定产品,如果跳过免费送货,可以使用以下代码段。
add_filter('woocommerce_package_rates', 'hide_shipping_method_if_particular_product_available_in_cart', 10, 2);
function hide_shipping_method_if_particular_product_available_in_cart($available_shipping_methods)
{
global $woocommerce;
// products_array should be filled with all the products ids
// for which shipping method (stamps) to be restricted.
$products_array = array(
101,
102,
103,
104
);
// You can find the shipping service codes by doing inspect element using
// developer tools of chrome. Code for each shipping service can be obtained by
// checking 'value' of shipping option.
$shipping_services_to_hide = array(
'free_shipping',
);
// Get all products from the cart.
$products = $woocommerce->cart->get_cart();
// Crawl through each items in the cart.
foreach($products as $key => $item) {
// If any product id from the array is present in the cart,
// unset all shipping method services part of shipping_services_to_hide array.
if (in_array($item['product_id'], $products_array)) {
foreach($shipping_services_to_hide as & $value) {
unset($available_shipping_methods[$value]);
}
break;
}
}
// return updated available_shipping_methods;
return
}
嘿那里,谢谢你的片段。我只需要免费送货超过250的轻产品。我需要拥有超过250个运输成本的重型产品。是包括那个片段吗?非常感谢 – spy
免费送货一定的最低金额可以通过Woocommerce设置。 –
重型产品ID可以添加到片段,并可以管理与slght改性中 –
- 1. 运费计算的项目重量和购物车的金额
- 2. Woocommerce所有购物车项目免费送货,如果航运类是在购物车
- 3. 贝宝购物车的送货费用之一
- 4. 购物车会话重复数量
- 5. Zen购物车送货估算师
- 6. 如何根据购物车中物品重量决定运送方式?
- 7. Woocommerce根据购物车数量和商品数量减少运费成本
- 8. 从WooCommerce购物车中删除存货数量错误信息
- 9. 更改每个购物车物品的重量以更新WooCommerce的运费
- 10. 更改购物车的数量
- 11. 获得了“免费送货”的方法最低订货量在结账页面
- 12. Woocommerce统一费率和免费送货
- 13. Magento按类别获取购物车中的物品数量
- 14. 数量和删除购物车中的物品
- 15. 如何更新购物车数量
- 16. 在购物车表中更新数量
- 17. 数量在亚马逊购物车?
- 18. 购物车数量没有更新
- 19. 购物车价按数量折扣
- 20. 向Magento购物车中添加免费礼物
- 21. 如何在“购物车”标签上显示添加到购物车的数量
- 22. magento购物车中允许的最低数量
- 23. 不能将数量从目录发送到购物车
- 24. 购物车最小化算法
- 25. Magento的:获取在购物车的数量给定产品
- 26. 免费送货在satchmo
- 27. 在Angular JS中获取所有购物车数量计数
- 28. 使用woocommerce获取wordpress中购物车的数量
- 29. 购物车会话和显示购物车中的物品数量返回undefined在Laravel
- 30. Magento在购物车中设置数量 - >数量不可用
所以你想购物车中的一些项目免费送货,但不是为了别人? –
请按照[mcve] –
编辑您的问题嘿,有点儿。我只需要免费送货超过250轻产品。我需要拥有超过250个运输成本的重型产品。 – spy