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
Add a comment  | 

1 Answer 1

Reset to default 0

You'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