在不删除 'view cart' 按钮的情况下编辑“%s 已添加到您的购物车”文本
Edit '%s has been added to your cart' text without removing 'view cart' button
我一直在尝试编辑“%s 已添加到您的购物车”文本,
没有真正的编码经验..
所以我尝试了一些我在网上找到的不同代码,
但他们似乎都删除了 'view cart' 按钮,我希望它保留。
有没有办法在不删除按钮的情况下编辑消息?
这是我使用的代码:
/**
* @snippet Edit "has been added to your cart" message
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WC 5
* @donate https://businessbloomer.com/bloomer-armada/
*/
add_filter( 'wc_add_to_cart_message_html', 'bbloomer_custom_add_to_cart_message' );
function bbloomer_custom_add_to_cart_message() {
$message = 'Nicely done!' ;
return $message;
}
提前致谢!
史蒂夫
您需要在过滤器中 return 的字符串中包含按钮的 HTML。例如:
add_filter( 'wc_add_to_cart_message_html', function ( $message ) {
$text = 'Product added to your cart.';
return sprintf(
'<a href="%s" tabindex="1" class="button wc-forward">%s</a> %s',
esc_url( wc_get_cart_url() ),
esc_html__( 'View cart', 'woocommerce' ),
esc_html( $text )
);
} );
替换“已添加到您的购物车的产品”。用你想要的文字。
我一直在尝试编辑“%s 已添加到您的购物车”文本, 没有真正的编码经验.. 所以我尝试了一些我在网上找到的不同代码, 但他们似乎都删除了 'view cart' 按钮,我希望它保留。
有没有办法在不删除按钮的情况下编辑消息?
这是我使用的代码:
/**
* @snippet Edit "has been added to your cart" message
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WC 5
* @donate https://businessbloomer.com/bloomer-armada/
*/
add_filter( 'wc_add_to_cart_message_html', 'bbloomer_custom_add_to_cart_message' );
function bbloomer_custom_add_to_cart_message() {
$message = 'Nicely done!' ;
return $message;
}
提前致谢! 史蒂夫
您需要在过滤器中 return 的字符串中包含按钮的 HTML。例如:
add_filter( 'wc_add_to_cart_message_html', function ( $message ) {
$text = 'Product added to your cart.';
return sprintf(
'<a href="%s" tabindex="1" class="button wc-forward">%s</a> %s',
esc_url( wc_get_cart_url() ),
esc_html__( 'View cart', 'woocommerce' ),
esc_html( $text )
);
} );
替换“已添加到您的购物车的产品”。用你想要的文字。