15 1 0 4000 1 https://codeblock.co.za 300 true 0

get_available_variations()

0 Comments

Framework / CMS

WooCommerce [Version: Since 3.0.0]

Syntax

Typical Usage

Gets all available variations for a particular product.

Accepted Parameters

  • return_type (string) (Optional) (Default = ‘array’): The data may be returned as an array of variation data or product objects.

Return Value(s)

Returns an array or \WC_Product_Variation[] objects depending on the specified return_type.

Notes

return_type may be ‘array’ or ‘objects’.

Hides out of stock variations if  ‘Hide out of stock items from the catalogue’ is checked in WooCommerce settings.

Examples of get_available_variations()

Example 1

<?php
$product = wc_get_product(1234);
$variations = $product->get_available_variations();
// OR 
$variations = $product->get_available_variations('array');

The above will return the product’s variations as an array.

Example 2

<?php
$product = wc_get_product(1234);
$variations = $product->get_available_variations('objects');

The above will return the product’s variations as objects.


Was This Helpful?

Previous Post
is_type()
Next Post
get_attributes()

0 Comments

Leave a Reply