我没有在WooCommerce的后端设置购物车链接。相反,我将购物车重定向到结帐页面。这工作得很好,但现在我结束了空url。当我向购物车中添加产品时,我得到的消息是"成功添加到购物车中,请在这里查看购物车"。'See the cart here'链接到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');
但这显然取代了整个添加到购物车消息。
谢谢。
您遗漏了一些代码。试试这样:
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;
}
你必须调整你的替代链接。您还可以更改文本…
引用:
- Hookr: wc_add_to_cart_message
- Woocommerce for WP中wc_add_to_cart_message钩子的替代方案
- 自定义添加到购物车消息- GitHub