woocommerce get list of attribute values

前端 未结 4 901

I\'m using woocommerce on wordpress to create a simple shop site and I\'ve added a couple attributes to a product. These are namely, size and color. Un

4条回答
  •  猫巷女王i
    2021-02-04 09:14

    Hoping this is helpful to someone:

    global $product; 
    
    // Get product attributes
    $attributes = $product->get_attributes();
    
    if ( ! $attributes ) {
        echo "No attributes";
    }
    
    foreach ( $attributes as $attribute ) {
    
            echo $attribute['name'] . ": ";
            $product_attributes = array();
            $product_attributes = explode('|',$attribute['value']);
    
            $attributes_dropdown = '';
    
            echo $attributes_dropdown;
    }
    

提交回复
热议问题