為您的商店提供免費(fèi)送貨服務(wù)是減少摩擦和最小化結(jié)賬放棄率的好方法。當(dāng)免費(fèi)選項(xiàng)可用時(shí),刪除其他運(yùn)費(fèi)(例如付費(fèi)選項(xiàng))是有意義的。在其他情況下,提供額外費(fèi)率(例如本地取貨和溢價(jià)/加急費(fèi)率)對(duì)客戶有利。
在這篇文章中,有不同的方法可以在免費(fèi)提供時(shí)隱藏其他運(yùn)費(fèi)。例如隱藏所有其他選項(xiàng)、僅隱藏付費(fèi)選項(xiàng)或某些特定費(fèi)率。
當(dāng)免費(fèi)送貨可用時(shí)隱藏所有運(yùn)費(fèi)選項(xiàng)
第一個(gè)片段是最簡(jiǎn)單的。隱藏所有其他運(yùn)輸選項(xiàng),使免費(fèi)送貨選項(xiàng)成為唯一可用的選項(xiàng)。這會(huì)檢查 WooCommerce 運(yùn)輸區(qū)中設(shè)置的“免費(fèi)送貨”方法,當(dāng)可用時(shí),它會(huì)隱藏除免費(fèi)送貨費(fèi)以外的所有運(yùn)費(fèi)選項(xiàng)。
<?php
/**
* Hide all shipping options when free shipping is available.
*
* @author Jeroen Sormani
* @link https://aceplugins.com/hide-shipping-rates-when-free-shipping-is-available-in-woocommerce/
*
* @param $available_methods
* @return array
*/
function js_hide_all_shipping_when_free_is_available( $shipping_rates ) {
foreach ( $shipping_rates as $key => $rate ) {
// Check if current rate is 'free_shipping'
if ( $rate->get_method_id() == 'free_shipping' ) {
$shipping_rates = array( $key => $rate );
}
}
return $shipping_rates;
}
add_filter( 'woocommerce_package_rates', 'js_hide_all_shipping_when_free_is_available' );
只有一種運(yùn)輸選項(xiàng)可用具有額外的好處,即客戶不必為運(yùn)輸做出任何額外的選擇。默認(rèn)情況下,WooCommerce 會(huì)顯示不同可用選項(xiàng)的單選按鈕,但只有一種運(yùn)費(fèi),它不會(huì)顯示為選項(xiàng)。
保留本地取件可用
在上面的代碼中,本地取貨選項(xiàng)被隱藏了。即使提供免費(fèi)送貨,客戶也可能更愿意取貨。這就是為什么這個(gè)代碼片段將是對(duì)上面的一個(gè)小的修改;通過(guò)此更改,它也將保留任何本地取件選項(xiàng)。
<?php
/**
* Hide all other shipping options when free shipping is available.
*
* @author Jeroen Sormani
* @link https://aceplugins.com/hide-shipping-rates-when-free-shipping-is-available-in-woocommerce/
*
* @param $available_methods
* @return array
*/
function js_hide_shipping_when_free_is_available( $shipping_rates ) {
$free_rates = array();
$free_available = false;
foreach ( $shipping_rates as $key => $rate ) {
// Check for free rates / don't take in account local pickup
if ( $rate->get_method_id() == 'free_shipping' && $rate->get_method_id() != 'local_pickup' ) {
$free_available = true;
}
if ( 0 == $rate->cost ) {
$free_rates[ $key ] = $rate;
}
}
// Show all free rates
if ( $free_available ) {
return $free_rates;
}
}
add_filter( 'woocommerce_package_rates', 'js_hide_shipping_when_free_is_available' );
在免費(fèi)可用時(shí)隱藏所有支付運(yùn)費(fèi)選項(xiàng)(含其他運(yùn)輸類型)
第一個(gè)和第二個(gè)代碼片段僅尋找“免費(fèi)送貨”方法。使用不同的解決方案(例如Advanced Free Shipping?或Advanced Shipping?插件)來(lái)創(chuàng)建免費(fèi)送貨選項(xiàng),之前的代碼段無(wú)法識(shí)別它。通過(guò)進(jìn)行一些更改,可以保留所有可用的免費(fèi)選項(xiàng),這些選項(xiàng)可以識(shí)別任何方法類型的費(fèi)率,包括免費(fèi)送貨、本地取貨和任何其他自定義送貨方式。
<?php
/**
* Hide all other shipping options when free shipping is available.
*
* @author Jeroen Sormani
* @link https://aceplugins.com/hide-shipping-rates-when-free-shipping-is-available-in-woocommerce/
*
* @param $available_methods
* @return array
*/
function js_hide_shipping_when_free_is_available( $shipping_rates ) {
$free_rates = array();
$free_available = false;
foreach ( $shipping_rates as $key => $rate ) {
// Check for free rates / don't take in account local pickup
if ( 0 == $rate->cost && $rate->get_method_id() != 'local_pickup' ) {
$free_available = true;
}
if ( 0 == $rate->cost ) {
$free_rates[ $key ] = $rate;
}
}
// Show all free rates
if ( $free_available ) {
return $free_rates;
}
}
add_filter( 'woocommerce_package_rates', 'js_hide_shipping_when_free_is_available' );
保留支付運(yùn)費(fèi)可用
到目前為止,我們一直隱藏所有支付運(yùn)費(fèi)。如果您為“常規(guī)”送貨選項(xiàng)提供免費(fèi)送貨服務(wù),提供 Premium 或 Expedited 選項(xiàng)可能有利于客戶更快地收到他們的產(chǎn)品。
在下面的代碼片段中,它將像前面的代碼片段一樣查找并保留所有免費(fèi)送貨選項(xiàng),但也可以保留某些(付費(fèi))運(yùn)費(fèi)。
<?php
/**
* Hide shipping options when free shipping is available.
*
* @author Jeroen Sormani
* @link https://aceplugins.com/hide-shipping-rates-when-free-shipping-is-available-in-woocommerce/
*
* @param $available_methods
* @return array
*/
function js_hide_shipping_when_free_is_available( $shipping_rates ) {
$show_rates = array();
$free_available = false;
$allowed_paid = array( 'flat_rate:62' ); // Shipping rate ID or instance ID
foreach ( $shipping_rates as $key => $rate ) {
// Check for free rates / don't take in account local pickup
if ( 0 == $rate->cost && $rate->get_method_id() != 'local_pickup' ) {
$free_available = true;
}
if ( 0 == $rate->cost || in_array( $rate->get_id(), $allowed_paid ) || in_array( $rate->get_instance_id(), $allowed_paid ) ) {
$show_rates[ $key ] = $rate;
}
}
// Show all free rates
if ( $free_available ) {
return $show_rates;
}
}
add_filter( 'woocommerce_package_rates', 'js_hide_shipping_when_free_is_available' );
注:文本內(nèi)容出自 aceplugins.com,由 WordPress大學(xué) 翻譯整理。
拓展閱讀:
- WooCommerce 優(yōu)惠券及促銷指南
- WooCommerce 帶動(dòng)顧客購(gòu)物的十種方法
- 如何禁用或隱藏WooCommerce優(yōu)惠券字段
- 6個(gè)好用的WooCommerce禮品卡插件
- 6個(gè)強(qiáng)大的WooCommerce優(yōu)惠券插件
- 6個(gè)好用的 WooCommerce 電子郵件自定義插件
- 5個(gè)好用的 WooCommerce 最小/最大數(shù)量插件





