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?
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);
}
}