Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get WooCommerce Product Attribute label name

Variable/variations in woocommerce products.

I can do this to get the attribute value from pa_size: <?php echo $product_variation->get_attributes()['pa_size']; ?> which is somewhere in /wp-admin/edit.php?post_type=product&page=product_attributes.

But how do I get the pa_size label (in this case: 'Size')? Have tried to fetch everything based on post_type, page and then the "term_group". But that won't work. I can see that this usually is visible per default, but this is a custom solution. Also in https://github.com/woocommerce/woocommerce/blob/3.8.0/templates/single-product/product-attributes.php I can't see where they print the actual label, only the "Attribute child label and value". But not actual parent (pa_size => Size).

Have googled like a maniac for hours now.

like image 746
sfsefsf33fs3fs3fs Avatar asked Oct 31 '25 03:10

sfsefsf33fs3fs3fs


1 Answers

To get the label name of a WooCommerce product attribute you will use one of the 2 following ways:

1) Using Woocommerce wc_attribute_label() dedicated function:

$taxonomy   = 'pa_size';
$label_name = wc_attribute_label( $taxonomy );

2) Using wordPress get_taxonomy() function:

$taxonomy   = 'pa_size';
$label_name = get_taxonomy( $taxonomy )->labels->singular_name;
like image 162
LoicTheAztec Avatar answered Nov 02 '25 20:11

LoicTheAztec