wordpress - Get all product variations of a product given its ID in Woocommerce -


i have custom page i'm trying list every products in store along variations.

also, i'm trying list variations' prices sorted product attribute slug 'size'

for testing, i'm trying variations of single product id 381 code yet is

    $handle=new wc_product('381');     $variations1=$handle->get_avaialable_variations();     foreach ($variations1 $key => $value) {             echo '<option  value="'.$value['variation_id'].'">'.implode('/',$value['attributes']).'-'.$value['price_html'].'</option>';      } 

but error i'm getting

php fatal error:  call undefined method wc_product::get_avaialable_variations()  

i tried using

$handle=new wc_product_variable('381'); 

instead of

 $handle=new wc_product('381');  

but error same.

any here?

try code.

    $handle=new wc_product_variable('12');         $variations1=$handle->get_children();         foreach ($variations1 $value) {         $single_variation=new wc_product_variation($value);             echo '<option  value="'.$value.'">'.implode(" / ", $single_variation->get_variation_attributes()).'-'.get_woocommerce_currency_symbol().$single_variation->price.'</option>'; } 

note: use $single_variation->get_price_html() outputs html span tag results in getting hidden in option tags.

tested above code , results follows.

let me know if worked too.

enter image description here


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -