admin管理员组文章数量:1122846
I've created CPT with my events and for each event I've created individual product in WooCommerce. Now I'm using this shortcode in my code
<?php echo do_shortcode('[add_to_cart id="'.get_field('event_ticket').'" show_price = "FALSE"]'); ?>
for displaying "add to basket" button placed on each event. Every event have Product Category "event" and now I want change default text on "add to basket" button, but only for those products which have 'event' Product Category.
How can I do that?
I've created CPT with my events and for each event I've created individual product in WooCommerce. Now I'm using this shortcode in my code
<?php echo do_shortcode('[add_to_cart id="'.get_field('event_ticket').'" show_price = "FALSE"]'); ?>
for displaying "add to basket" button placed on each event. Every event have Product Category "event" and now I want change default text on "add to basket" button, but only for those products which have 'event' Product Category.
How can I do that?
Share Improve this question asked Jan 7, 2019 at 14:54 DamianDamian 971 silver badge11 bronze badges 3- Hi Damian, questions regarding WooCommerce are off-topic here... – Krzysiek Dróżdż Commented Jan 8, 2019 at 7:25
- I have seen many posts about WooCommerce here so I let myself to write... – Damian Commented Jan 9, 2019 at 0:13
- they’re getting closed, but not quick enough ;) – Krzysiek Dróżdż Commented Jan 9, 2019 at 7:18
1 Answer
Reset to default 0You're going to want to filter the text. here's the function from core WC that builds that text. In both of these instances $this
will be the product.
/**
* Get the add to cart button text for the single page.
*
* @access public
* @return string
*/
public function single_add_to_cart_text() {
return apply_filters( 'woocommerce_product_single_add_to_cart_text', $this->get_button_text() ? $this->get_button_text() : _x( 'Buy product', 'placeholder', 'woocommerce' ), $this );
}
/**
* Get the add to cart button text.
*
* @access public
* @return string
*/
public function add_to_cart_text() {
return apply_filters( 'woocommerce_product_add_to_cart_text', $this->get_button_text() ? $this->get_button_text() : _x( 'Buy product', 'placeholder', 'woocommerce' ), $this );
}
So you're going to want to add a filter to either woocommerce_product_single_add_to_cart_text
or woocommerce_product_add_to_cart_text
that checks if $this
is an event and changes the text if it is or returns the default text if it isn't.
本文标签: How to change quotadd to basketquot button text in WooCommerce based on product category
版权声明:本文标题:How to change "add to basket" button text in WooCommerce based on product category? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736290308a1928485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论