I’m using Woocommerce and when the payment is being made, this function is executed and it works correctly, but what I need is for the value of the custom field to be returned when executing the foreach. What function returns the content of the field, I tried the_field('comboitems')
but without success.
function example_metadata( $metadata, $order, $post ) {
foreach ( $order->get_items() as $item_id => $item ) {
$metadata['test'] = '1234';
$metadata['field1'] = $item->get_data();
$metadata['customfield'] = the_field('comboitems');
}
return $metadata;
}
This $item->get_data()
was an attempt to check if the comboitems custom field was read.
I used the command $item->get_data();
in an attempt to see if it returned something related to my field.. I tried using the_field(‘comboitems’) but it returned NULL, as well as other variations in search of a solution.
2
Answers
LoicTheAztec, how can I make when don't is custom field but an attribute?
Don’t use
the_field()
function as it echoes a custom field. Use insteadget_field()
to assign a custom field value to a variable…Then from an order item (product), you will use:
So in your code: