get_available_variations()
14th January 2021
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.
Used In Projects
Was This Helpful?
If this post has helped you, please let me know. Your feedback will be highly appreciated and will help me build better content.