customization - WooCommerce - Adding custom HTML to specific product pages

admin2025-06-05  1

I'm trying to add some custom HTML to specific WooCommerce products for my client. I successfully learned to add this custom HTML to all product pages at once (more specifically to their descriptions, overriding short-description.php) but I only need products A, B and C to contain this HTML bit and the rest to stay with the default content. A, B and C are in the same product category. How would you narrow the products, via category or product by product, that will contain this HTML, please?

I'm trying to add some custom HTML to specific WooCommerce products for my client. I successfully learned to add this custom HTML to all product pages at once (more specifically to their descriptions, overriding short-description.php) but I only need products A, B and C to contain this HTML bit and the rest to stay with the default content. A, B and C are in the same product category. How would you narrow the products, via category or product by product, that will contain this HTML, please?

Share Improve this question asked Jul 21, 2016 at 20:51 Luiz CruzLuiz Cruz 231 gold badge1 silver badge7 bronze badges 1
  • check the documentation to add something for a particular posts/pages/category codex.wordpress/Conditional_Tags – Aftab Commented Jul 21, 2016 at 21:49
Add a comment  | 

2 Answers 2

Reset to default 0

check the documentation to add something for a particular posts/pages/category http://codex.wordpress/Conditional_Tags

You can check woocommerce related conditional tag here -

https://docs.woocommerce/document/conditional-tags/

You can try below code. In this code add_action execute only when product have category like men or women.

function wp_extracode_for_products()
{
  echo'your code'; 
}

add_action( 'wp', 'remove_product_content' );

function remove_product_content() {

  if ( is_product() && (has_term( 'men', 'product_cat' )|| has_term( 'women', 'product_cat' ) )) {

   add_action('woocommerce_single_product_summary', 'wp_extracode_for_products', 60);

  }
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749066370a316062.html

最新回复(0)