I want to know if it is possible to get all variations from a product – both available variations and unavailable variations. For example if a variation doesn’t have a price set, it will be marked as unavailable.
When I call $product->get_available_variations()
it only returns the available variations. Any way to get unavailable variations as well?
2
Answers
Solved:
I managed to get all variation ids by calling
$product->get_children()
To get all variations of a product you can make an API call using the
wc_get_product()
function to get the product object and then use theget_available_variations()
method to get the available variations or theget_children()
method to get all variations, both available and unavailable.Here is an example of how this can be done:
This will retrieve all variations for the product with the specified ID, and loop through each one, checking if it is in stock and purchasable, marking as available or unavailable accordingly.