我想在每个产品的商店商店页面上显示我选择的一些特定产品属性.必须显示属性的名称并与其值相反.我开始编写代码,我想打印至少名称,但我只显示最后一个属性的名称
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;
}
Run Code Online (Sandbox Code Playgroud) 必须使用键[0]从数组中获取值,但是数组在对象中。如何将其放入变量中?
WC_Product_Variable Object ( [children:protected] => Array ( [0] => 344 [1] => 345 ) [visible_children:protected] => Array ( [0] => 344 [1] => 345 )
Run Code Online (Sandbox Code Playgroud)