在特定类别的下面的单一产品上显示内容

时间:2019-05-02 作者:Raashid Din

我想在wooocommerce的单一产品页面中添加一些内容。但我不知道怎么做。

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
    }
}
我申请的是产品类别。但我的逻辑是,这些内容应该只显示给带有catgeory“手机套”的产品。我将如何做到这一点。提前感谢

1 个回复
最合适的回答,由SO网友:nmr 整理而成

您可以检查当前帖子是否在mobile-covers 以这种方式分类:

if ( has_term(\'mobile-covers\', \'product_cat\') )
In the documentation, 您可以阅读is_product_category () 功能:

查看时返回trueproduct category.

因此,在单个产品页面上使用总是会返回FALSE。

相关推荐