繁体   English   中英

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

[英]How to add product attributes in woocommerce product lisitng page in wordpress?

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

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

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

编辑:

我误会了你 应该这样做(在我的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM