I want to add some content to single products page in wooocommerce. But I don't know how to do it.
add_action('woocommerce_after_single_product','woo_after_product');
function woo_after_product() {
if(is_product_category('mobile-covers')) {
?>
<div class="specs-wrapper">
<div class="img-wrapper">
<img class="spec-img" src=".png" alt="Product size and specs">
</div>
<div class="content-wrapper">
<ul class="p-desc">
<li>
<p class="spec-title">1. Complete protection
</p>
<p class="spec-content">Impact-resistant, durable hard plastic case with an extremely slim profile, with raised front bezel for extra screen protection.
</p>
</li>
<li>
<p class="spec-title">2. High quality printing
</p>
<p class="spec-content">Expect no peeling, chipping, or wearing off.
</p>
</li>
<li>
<p class="spec-title">3. Free access to buttons
</p>
<p class="spec-content">Complete access to all standard buttons and ports, tailored for your device.
</p>
</li>
<li>
<p class="spec-title">4. All side design
</p>
<p class="spec-content">Case covers 100% of the outer surface of the phone, precision moulded with no seams or sharp edges.
</p>
</li>
</ul>
</div>
</div>
<?php
}
}
as i am applying is product category. But my logic is that this content should be only shown to products with catgeory "Mobile Covers". How will I do that. Thanks in advance
I want to add some content to single products page in wooocommerce. But I don't know how to do it.
add_action('woocommerce_after_single_product','woo_after_product');
function woo_after_product() {
if(is_product_category('mobile-covers')) {
?>
<div class="specs-wrapper">
<div class="img-wrapper">
<img class="spec-img" src="http://uperfect.co/wp-content/uploads/2019/04/transparentDiamond_1.png" alt="Product size and specs">
</div>
<div class="content-wrapper">
<ul class="p-desc">
<li>
<p class="spec-title">1. Complete protection
</p>
<p class="spec-content">Impact-resistant, durable hard plastic case with an extremely slim profile, with raised front bezel for extra screen protection.
</p>
</li>
<li>
<p class="spec-title">2. High quality printing
</p>
<p class="spec-content">Expect no peeling, chipping, or wearing off.
</p>
</li>
<li>
<p class="spec-title">3. Free access to buttons
</p>
<p class="spec-content">Complete access to all standard buttons and ports, tailored for your device.
</p>
</li>
<li>
<p class="spec-title">4. All side design
</p>
<p class="spec-content">Case covers 100% of the outer surface of the phone, precision moulded with no seams or sharp edges.
</p>
</li>
</ul>
</div>
</div>
<?php
}
}
as i am applying is product category. But my logic is that this content should be only shown to products with catgeory "Mobile Covers". How will I do that. Thanks in advance
Share Improve this question asked May 2, 2019 at 10:01 Raashid DinRaashid Din 2182 silver badges19 bronze badges 3- This looks reasonable to me. You're saying it doesn't work? Is your hook getting called, is the check not working, is the content going in the wrong place, something else? – Rup Commented May 2, 2019 at 10:06
- i want to show content on single products not on category page. – Raashid Din Commented May 2, 2019 at 10:20
- OK. Do you mean that this content is appearing on the category page too and you don't want it to? Or the is_product_category check isn't working on the single products page? Maybe you should modify the single product page template instead rather than trying to do this with a hook. – Rup Commented May 2, 2019 at 10:35
1 Answer
Reset to default 1You can check whether the current post is in the mobile-covers
category in this way:
if ( has_term('mobile-covers', 'product_cat') )
In the documentation, you can read about the is_product_category ()
function that:
Returns true when viewing a product category.
therefore, used on single product page always will return FALSE.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745532201a4631746.html
评论列表(0条)