在将产品添加到购物车后重新加载产品页面后,顶部会显示一条通知,指出“产品已添加到购物车”,然后是“查看购物车”按钮。
但是将产品添加到购物车后,我想引导客户访问结帐页面(我将在其中添加购物车页面功能),而不是购物车页面。如何将通知的购物车链接替换为结帐页面的链接?
wc_add_to_cart_message()
函数(在includes/wc-cart-functions.php
中)似乎会生成此特定通知,我应该重写此函数吗?如果是这样,如何?
尝试一下...
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);
脚本也为我工作,谢谢你。是否可以在消息中添加“查看购物车”和“继续结帐”?