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?

  • Hi Damian, questions regarding WooCommerce are off-topic here... – Krzysiek Dróżdż Jan 8 at 7:25
  • I have seen many posts about WooCommerce here so I let myself to write... – Damian Jan 9 at 0:13
  • they’re getting closed, but not quick enough ;) – Krzysiek Dróżdż Jan 9 at 7:18
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, privacy policy and cookie policy

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