Ian Batten
Ian Batten

Reputation: 211

Display custom product attribute value in WooCommerce product page

I will be adding custom product attributes to the product data for products in my woocommerce catalogue.

How can I fetch the values of this field to display in the product page/template?

Thanks

enter image description here

Upvotes: 1

Views: 574

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 254373

You could use the following using WC_Product get_attribute() method:

global $product; // if the WC_Product object is not defined

if ( ! is_a($product, 'WC_Product') ) {
    $product = wc_get_product( get_the_ID() );
}

echo  '<p>' . $product->get_attribute( 'secimg' ) . '</p>';

Its should work.

Upvotes: 3

Related Questions