当单击添加到购物车按钮时,Woocommerce 会显示消息,查看购物车,我想编辑此消息,实际编辑所有跨度,放置一些图标等...
最佳答案
将过滤器添加到您的主题/functions.php。下面的代码只是覆盖了现有的 $message。这会用几乎相同的消息覆盖 $message ,该消息在消息之前添加了“结帐”链接。
确保您返回 $message。
您当然可以只修改现有消息,因为整个消息通过第一个参数或 $message var 作为字符串传递。
add_filter ( 'wc_add_to_cart_message', 'wc_add_to_cart_message_filter', 10, 2 );
function wc_add_to_cart_message_filter($message, $product_id = null) {
$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 ) );
$message = sprintf( '%s <a href="%s" class="button">%s</a> <a href="%s" class="button">%s</a>',
esc_html( $added_text ),
esc_url( wc_get_page_permalink( 'checkout' ) ),
esc_html__( 'Checkout', 'woocommerce' ),
esc_url( wc_get_page_permalink( 'cart' ) ),
esc_html__( 'View Cart', 'woocommerce' ));
return $message;
}
关于wordpress - Woocommerce,如何编辑 "added to cart"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25880460/