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

get_attributes()

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

Was This Helpful?

Previous Post
get_available_variations()
Next Post
wc_get_product_id_by_sku()

0 Comments

Leave a Reply