在woocommerce产品页面中显示产品属性和分类 [英] display product attribute and taxonomy in woocommerce product page

查看:84
本文介绍了在woocommerce产品页面中显示产品属性和分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示产品页面上附加信息"中的品牌"属性.有没有一种方法可以创建一个简码,因为我有一个特定的位置来显示它甚至在php中.

I want to display the Brand attribute from the Additional Info on the product page. Is there a way to create a shortcode because i have a specific location to display it or even in php.

这是用于woocommerce 3.6.5

This is for woocommerce 3.6.5

提前谢谢

推荐答案

您可以在活动主题的functions.php中添加以下代码片段以完成上述操作-

You can add the follows code snippet in your active theme's functions.php to do the above -

// to display product additional info in product page
add_action( 'woocommerce_single_product_summary', 'show_additional_info_product_summary', 45 );
// To diplay additonal info via shortcode within product page
add_shortcode( 'show_additional_info', 'show_additional_info_product_summary' );
function show_additional_info_product_summary() {
    global $product;
    // Assume that your attribute is pa_brand
    $brand_attributes = $product->get_attribute('brand');
    ?>
    <table class="woocommerce-product-attributes shop_attributes">
        <tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--brand">
            <th class="woocommerce-product-attributes-item__label"><?php echo ucfirst( 'brand' ); ?></th>
            <td class="woocommerce-product-attributes-item__value"><?php echo $brand_attributes; ?></td>
        </tr>
    </table>
    <?php
}
// to remove additional info tab
add_filter( 'woocommerce_product_tabs', 'remove_additional_info_tab', 99 );
function remove_additional_info_tab( $tab ) {
    if( isset( $tab['additional_information'] ) ) unset( $tab['additional_information'] );
    return $tab;
}

这篇关于在woocommerce产品页面中显示产品属性和分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆