回答
這個自定義代碼將保持免費送貨方法,並隱藏其他的運輸方式時,車量最多爲,如果產品不重(小於超過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. 運費計算的項目重量和購物車的金額
- 3. Magento購物車的最低數量
- 4. Woocommerce所有購物車項目免費送貨,如果航運類是在購物車
- 5. 貝寶購物車的送貨費用之一
- 6. 購物車會話重複數量
- 7. 免費送貨購物車規則不支持socolissimoflexibilite(法國)承運人
- 8. 購物車編輯數量
- 9. Zen購物車送貨估算師
- 10. 如何根據購物車中物品重量決定運送方式?
- 11. Woocommerce根據購物車數量和商品數量減少運費成本
- 12. 打開購物車免費運送異常
- 13. woocommerce根據數量增加到購物車的收費
- 14. 從WooCommerce購物車中刪除存貨數量錯誤信息
- 15. 更改每個購物車物品的重量以更新WooCommerce的運費
- 16. Virtuemart免費送貨
- 17. 添加運送到購物車時請考慮購物車的重量和價格
- 18. 如何獲取購物車頁面中的批量數量?
- 19. Magento - 根據產品重量免費送貨
- 20. Woocommerce統一費率和免費送貨
- 21. 獲得了「免費送貨」的方法最低訂貨量在結賬頁面
- 22. 更改購物車的數量
- 23. Magento的購物車數量不可
- 24. 購物車在codeigniter中,更改產品數量和更新購物車
- 25. Magento按類別獲取購物車中的物品數量
- 26. Magento免費送貨,免運費
- 27. 數量和刪除購物車中的物品
- 28. 向Magento購物車中添加免費禮物
- 29. 購物車數量沒有更新
- 30. 放入購物車數量邏輯RoR
所以你想購物車中的一些項目免費送貨,但不是爲了別人? –
請按照[mcve] –
編輯您的問題嘿,有點兒。我只需要免費送貨超過250輕產品。我需要擁有超過250個運輸成本的重型產品。 – spy