在将产品添加到购物车后重新加载产品页面后,会在顶部显示一条通知,说明"产品已添加到购物车"然后是一个"查看购物车"按钮。
但是,在将产品添加到购物车后,我希望将客户引导到结帐页面(我将添加购物车页面功能),而不是购物车页面。如何通过指向结帐页面的链接替换通知的购物车链接?
wc_add_to_cart_message()
函数(在includes/wc-cart-functions.php
中)似乎会生成此特定通知,我应该覆盖此函数吗?如果是这样,怎么样?
答案 0 :(得分:2)
试试这个......
function rei_wc_add_to_cart_message( $message, $product_id ) {
$titles = array();
if ( is_array( $product_id ) ) {
foreach ( $product_id as $id ) {
$titles[] = get_the_title( $id );
}
} else {
$titles[] = get_the_title( $product_id );
}
$titles = array_filter( $titles );
$added_text = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $titles ) );
// Output success messages
if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
$return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
$message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue Shopping', 'woocommerce' ), esc_html( $added_text ) );
} else {
$message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( wc_get_page_permalink( 'checkout' ) ), esc_html__( 'Proceed to Checkout', 'woocommerce' ), esc_html( $added_text ) );
}
return $message;
}
add_filter('wc_add_to_cart_message','rei_wc_add_to_cart_message',10,2);