ใน 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');
พวกเขาแสดงเฉพาะชื่อฟิลด์แอตทริบิวต์เป็น pa_size
, pa_color
ฉันจะรับและแสดงค่าสำหรับคุณลักษณะของผลิตภัณฑ์นั้นได้อย่างไร (เช่น 2kg
, 3kg
หรือ blue
, green
) ?
ขอบคุณ.