【问题标题】:display product attribute and taxonomy in woocommerce product page在 woocommerce 产品页面中显示产品属性和分类
【发布时间】:2020-01-25 00:34:54
【问题描述】:

我想在产品页面的附加信息中显示品牌属性。有没有办法创建一个短代码,因为我有一个特定的位置来显示它,甚至在 php.ini 中。

这适用于 woocommerce 3.6.5

提前谢谢你

【问题讨论】:

    标签: php wordpress woocommerce attributes taxonomy


    【解决方案1】:

    您可以在活动主题的functions.php中添加以下代码sn-p来执行上述操作-

    // 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;
    }
    

    【讨论】:

    • 感谢您的回复。我只想从中获取 Brand 属性并将其显示在产品页面上,而不是整个属性集。
    • @markswta 我根据您的需要更新了我的答案。请检查。
    猜你喜欢
    • 2017-06-14
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多