脚本宝典收集整理的这篇文章主要介绍了php – 在Woocommerce存档页面上显示特定的产品属性,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
add_action('woocommerce_after_shop_loop_ITem','add_attribute'); function add_attribute() { global $PRoduct; $weigth_val = $product->get_attribute('weight'); $quant_val = $product->get_attribute('quantity'); $length_val = $product->get_attribute('length'); echo $weigth_val; echo $quant_val; echo $length_val; }
该分类名称将与WC_Product get_attribute()方法一起使用.
add_action('woocommerce_after_shop_loop_item','displaying_product_attributes'); function displaying_product_attributes() { global $product; $weigth_val = $product->get_attribute('pa_weight'); $quant_val = $product->get_attribute('pa_quantity'); $length_val = $product->get_attribute('pa_length'); echo $weigth_val; echo $quant_val; echo $length_val; }
它现在应该工作……
add_action('woocommerce_after_shop_loop_item','add_attribute'); function add_attribute() { global $product; $product_attributes = array( 'pa_weight','pa_quantity','pa_length','pa_color' ); $attr_output = array(); // Loop through the array of product attributes foreach( $product_attributes as $taxonomy ){ if( taxonomy_exists($taxonomy) ){ $label_name = get_taxonomy( $taxonomy )->labels->singular_name; $value = $product->get_attribute('pa_weight'); if( ! empty($value) ){ // Storing attributes for output $attr_output[] = '<span class="'.$taxonomy.'">'.$label_name.': '.$value.'</span>'; } } } // Output attribute name / value pairs separate by a "<br>" echo '<div class="product-attributes">'.implode( '<br>',$attr_output ).'</div>'; }
以上是脚本宝典为你收集整理的php – 在Woocommerce存档页面上显示特定的产品属性全部内容,希望文章能够帮你解决php – 在Woocommerce存档页面上显示特定的产品属性所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。