admin管理员组文章数量:1130349
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
2 Answers
Reset to default 0check 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);
}
}
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
2 Answers
Reset to default 0check 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);
}
}
本文标签: customizationWooCommerceAdding custom HTML to specific product pages
版权声明:本文标题:customization - WooCommerce - Adding custom HTML to specific product pages 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749066346a2310876.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论