get_attributes()
18th January 2021
0 Comments
Framework / CMS
WooCommerce [Version: Since 3.0.0]
Syntax
Typical Usage
Getting all of the attributes for a given product.
Accepted Parameters
context (string) (Optional): What the value is for. Valid values are ‘view’ and ‘edit’.
Return Value(s)
Returns an array of attributes for the product.Notes
Not to be confused with get_attribute() which returns the value of a single queried attribute.
Examples of get_attributes()
Example 1
<?php
$product = wc_get_product( get_the_ID() );
$atts = $product->get_attributes();
foreach($atts as $att) {
$options = $att->get_options();
echo $att->get_name() . ':<br>';
foreach( $options as $option) {
echo $option . '<br>';
}
}
The above will output something like this:
Size:
250ml
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.