M
M
midas342020-08-31 14:13:35
WordPress
midas34, 2020-08-31 14:13:35

How to display different text under the add_to_cart button for different product categories?

I want to display different text under the buy button, in different categories, on the product page example

add_action( 'woocommerce_after_add_to_cart_button', 'mytext_after_add_to_cart_button', 50);
function mytext_after_add_to_cart_button() {
if( is_product_category( 'coffee' ) ) {
  echo '<div class="get-mytext-form"><a href="/mytext-form1/">Need help with form1?</a></div>';
} else {
  echo '<div class="get-mytext-form2"><a href="/mytext-form2/">Need help with form2?</a></div>';
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Zagainov, 2020-09-01
@midas34

https://github.com/woocommerce/woocommerce/blob/ma...
You can hook your function to the woocommerce_single_product_summary hook with a priority of 35 and your label will appear right after the button

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question