简体   繁体   English

如何在 Woocommerce 中的 wc_add_to_cart_message 中添加一个额外的按钮?

[英]How can I add an extra button the the wc_add_to_cart_message in Woocommerce?

I want to add a continue shopping button to the Add to Cart message that pops up after someone adds a product to the cart.我想在有人将产品添加到购物车后弹出的“添加到购物车”消息中添加一个继续购物按钮。 I can change the current "View cart" button to a continue shopping button using this code:我可以使用以下代码将当前的“查看购物车”按钮更改为继续购物按钮:

add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
    global $woocommerce;
    $return_to  = get_permalink(woocommerce_get_page_id('shop'));
    $message    = sprintf('<a href="%s" class="button wc-forwards">%s</a> %s', $return_to, __('Continue shopping', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
    return $message;
}

But I want to add an additional button and keep the "View Cart" button too.但我想添加一个额外的按钮并保留“查看购物车”按钮。

Thanks谢谢

Add the follows code snippet in your active theme's functions.php -在活动主题的函数中添加以下代码片段。php -

function modify_wc_add_to_cart_message_html( $message, $products ) {
    $message = sprintf( '<a href="%s" tabindex="1" class="button wc-forward" style="margin-left: 10px;">%s</a> %s',esc_url( wc_get_page_permalink( 'shop' ) ), esc_html__( 'Continue shopping', 'woocommerce' ), $message );
    return $message;
}
add_filter( 'wc_add_to_cart_message_html', 'modify_wc_add_to_cart_message_html', 99, 2 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何用图标替换“添加到购物车”文本(添加到购物车按钮woocommerce) - How can i replace text “Add to cart” with an icon (Add to cart button woocommerce) WooCommerce-如何使用具有相同购物车按钮的Ajax将多种不同的产品添加到购物车? - WooCommerce - How can I add multiple, different products to cart using ajax with same add-to-cart-Button? 在WooCommerce中为特定产品添加额外添加到购物车按钮 - Add extra add to cart button to specific products in WooCommerce 在 Woocommerce 3 商店页面上的添加到购物车下添加额外按钮 - Add Extra button under Add to cart on shop page of Woocommerce 3 Woocommerce:如何在woocommerce_add_to_cart钩子上wc_add_order_item_meta? - Woocommerce: how to wc_add_order_item_meta on woocommerce_add_to_cart hook? 在Woocommerce价格下面添加额外的添加到购物车按钮 - Adding Extra Add to cart button below Woocommerce Price WooCommerce:如何在常规页面上使用“添加到购物车”按钮? - WooCommerce: How do I use an Add to Cart button on a normal page? 在 Woocommerce 中的产品摘要下方添加额外的添加到购物车按钮 - Adding Extra Add to cart button below product summary in Woocommerce 如何在Woocommerce页面顶部添加购物车按钮? - How to add the Cart button on top of the page in Woocommerce? 在Woocommerce 3中自定义添加到购物车消息 - Customizing add to cart message in Woocommerce 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM