2016-06-28 77 views
1

我在WooCommerce的後端沒有設置購物車鏈接。相反,我將購物車重定向到結帳頁面。這工作正常,但現在我結束了空的網址。當我將產品添加到購物車時,我會看到「成功添加到購物車中的消息,在此處查看購物車」。 '在這裏看到購物車'鏈接到wc_get_page_permalink('cart'),但這沒有設置。當購物車不空時設置購物車鏈接

只有當物品在購物車中時,是否可以通過函數設置wc_get_page_permalink('cart')

我想是這樣的:

function custom_continue_shopping_redirect_url ($product_id) { 
    $url = "http://www.url.com"; // Add your link here 
    return $url; 
} 
add_filter('wc_add_to_cart_message', 'custom_continue_shopping_redirect_url'); 

但是,這顯然是更換整個添加到購物車信息。

謝謝。

回答

2

您錯過了一些代碼。試試吧:

add_filter('wc_add_to_cart_message', 'custom_continue_shopping_redirect_url', 10, 2); 
function custom_continue_shopping_redirect_url($message, $product_id) { 
    global $woocommerce; 

     // $permalink = get_permalink(woocommerce_get_page_id('shop')); // replaced by: 
     $permalink = get_permalink(woocommerce_get_page_id('cart')); // your link here. 
     $message = sprintf('<a href="%s" class="button wc-forwards">%s</a> %s', $permalink, __('Continue Shopping', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce')); 
    return $message; 
} 

你將不得不微調你的替換鏈接。您也可以改變文字...

參考文獻: