0

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?

3
  • Hi Damian, questions regarding WooCommerce are off-topic here... 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 ;) Commented Jan 9, 2019 at 7:18

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.