Woocommerce,如何编辑“添加到购物车”信息

编程入门 行业动态 更新时间:2024-10-11 13:22:36
本文介绍了Woocommerce,如何编辑“添加到购物车”信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当单击添加到购物车按钮时,Woocommerce显示消息,查看购物车,我要编辑此消息,实际上是编辑所有范围,并放置一些图标,等等。

When click on add to cart button, the Woocommerce shows the message, view cart, I want to edit this message, actually edit all the span, put some icon etc...

推荐答案

向您的theme / functions.php添加过滤器。下面的代码仅覆盖现有的$ message。这样会用几乎相同的$ message覆盖$ message,并在其前面加上结帐链接。

Add a filter to your theme/functions.php. The code below just overrides the existing $message. This overwrites $message with an nearly identical one that prepends a "checkout" link to the message.

请确保您返回$ message。

Make sure you return the $message.

您当然可以修改现有消息,因为整个事情都是通过第一个参数或$ message var作为字符串传递的。

You can of course just modify the existing message, as the entire thing is passed as a string via the first param or $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>&nbsp;<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; }

更多推荐

Woocommerce,如何编辑“添加到购物车”信息

本文发布于:2023-11-24 21:53:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:购物车   编辑   信息   Woocommerce

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!