【问题标题】:Show specific product attributes on single product page (WooCommerce) [closed]在单个产品页面上显示特定的产品属性(WooCommerce)[关闭]
【发布时间】:2021-10-20 12:54:11
【问题描述】:

我想在 WooCommerce 的单个产品页面上显示特定属性。

我正在使用Get specific product attribute and display it in Woocommerce Single Product Pages 答案代码

问题是:如何在现有代码中添加更多属性?

【问题讨论】:

    标签: php wordpress woocommerce product custom-taxonomy


    【解决方案1】:

    这是添加更多属性的方法

    add_action( 'woocommerce_single_product_summary', 'product_attribute_dimensions', 45 );
    function product_attribute_dimensions(){
        global $product;
    
        $taxonomies = array('pa_size','pa_color'); //add your attributes
        //Then we loop each of them
        foreach($taxonomies as $taxonomy){
            $value = $product->get_attribute( $taxonomy );
            if ( $value ) {
                $label = get_taxonomy( $taxonomy )->labels->singular_name;
        
                echo '<p>' . $label . ': ' . $value . '</p>';
            }
        }
    }
    

    【讨论】: