如何在wordpress的woocommerce产品lisitng页面中添加产品属性?

时间:2015-07-16 08:10:08

标签: php wordpress woocommerce

我正在使用wordpress中的woocommerce插件开发购物车网站。在产品中我有两个属性,如SIZE和COLOR。

目前产品名称和价格显示在产品列表页面dafault.now我想在产品列表页面中的价格下面添加SIZE属性。

我知道要添加钩子,但我不知道如何使用钩子添加SIZE?

1 个答案:

答案 0 :(得分:1)

编辑:

我误解了你。这应该做(在我的woocommerce测试页面上检查):

if (!function_exists('shop_attributes_in_loop')) {
    function shop_attributes_in_loop(){
        global $product;
            $attributes = $product->get_attributes();
            if(!empty($attributes)){
                $attribute_single = array_keys($attributes);
                $myArray = array();
            echo '<div class="product_attributes">';
                foreach ($attribute_single as $attribute => $value) {
                    $myArray[] = ucfirst($value);
                }
            echo implode(', ', $myArray).'</div>';
            }
    }
}


add_action('woocommerce_after_shop_loop_item', 'shop_attributes_in_loop');

这会将您的商品属性(如果存在)放入div .product_attrributes中。您可以轻松添加可翻译的字符串,表示这些是产品属性,如

echo esc_html('Product attributes', 'my-theme-name') .'<div class="product_attributes">'

在第一个echo

相关问题