Ecommerce Shopify WordPress Discussion

Get WooCommerce product attribute value from Order item

Read attribute content of a product. I am including within the JSON of the order that is being processed in WooCommerce the value of the attribute of the product that is being processed, I have already managed to get the content of a custom field see this link, but I have not yet been able to get the content of an attribute that it would even be from this same product. function example_metadata( $metadata, $order, $post ) { foreach ( $order->get_items() as $item_id => $item ) { $metadata['atrib'] =$item->get_product_id()->get_attribute( 'split' ); $product = wc_get_product(); $metadata['atrib1'] = $item_id->get_attribute( 'split' ); } return $metadata; }
As get_attribute() is a WC_Product method, it has to be used with a WC_Product Object… Try the following instead: function example_metadata( $metadata, $order, $post ) { foreach ( $order->get_items() as $item ) { $product = $item->get_product(); $value = $product->get_attribute('split'); if ( $item->get_variation_id() > 0 && empty($value) ) { $product = wc_get_product($item->get_product_id()); $value = $product->get_attribute('split'); } $metadata['atrib'] = $value; } return $metadata; } It could work. If it doesn't work, try to use the product attribute label name instead of the slug, maybe like "Split" instead of "split".

January 10, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.