Im working with the single product page and I need to have a different image (depending on the category) after the add to cart button.
I tried this code but it doesn’t show me the image that I need
add_action ( 'woocommerce_after_add_to_cart_button', 'content_after_button' );
function content_after_button() {
if (has_term( 'Categoria', 'Accesorios' ) ) {
echo 'https://prueba.soygorrion.com.ar/wp-content/uploads/2019/08/iconos2.jpg';
}
I think im using has_term in the wrong way.
What im trying to accomplish is:
I have a parent category that is “Accesorios” and inside that I have other child categories like “Billeteras”. For each one of this child categories it has to show a diferent image.
thank you
2
Answers
Since you mentioned that the problem is with has_term function. If you can get the product ID inside add to cart, then you can use this code to get categories and check them:
I have tested this code for another purpose, it works fine. I hope this will help. Please inform me when you test it and if you face any errors update your question with your new code.
First of all there is issue with your
has_term
checking. If you check has_term docs, you can find it takes first parameter as category term and second parameter as taxonomy.Add secondly you are just echo image url that is not going to display image.
So, do as follows –