WooCommerce, 實用技巧

WooCommerce 清空購物車返回訊息+網址修改

WooCommerce 清空購物車返回訊息+網址修改

隨手筆記,我覺得我不知道民國幾年還會有機會用到這串修改語法。

這次的案例是客戶想修改清空購物車後,會有一顆按鈕「返回商店」網址是 /shop/

我個人是覺得客戶客製很多小地方其實不太必要,但遇到了就是得修改 🙁

WooCommerce 清空購物車返回訊息+網址修改
上圖是已經修改完成的樣子,心好累。

所幸修改很簡單,兩段語法可以解決這個部分,主要是利用「woocommerce_return_to_shop_redirect」與「woocommerce_return_to_shop_text」就可以處理了。

語法如下:

//修改返回SHOP網址
add_filter( 'woocommerce_return_to_shop_redirect', 'uni_woo_return_to_shop_button_modify' );
function uni_woo_return_to_shop_button_modify() {
    $url = 'https://www.your-url.com'; 
    return $url;
}

//修改按鈕文字
add_filter('woocommerce_return_to_shop_text', 'uni_woo_shop_button_text_modify');
function uni_woo_shop_button_text_modify() {
    $shop_button_text = "回到首頁"; 
    return $shop_button_text;
}

woocommerce_return_to_shop_redirect 負責處理網址的修改,預設是「/shop」商品頁面,我們直接改網址就可以了。

相關文章