ResolvedFood Addon Values to PHP?
- This topic has 4 replies, 3 voices, and was last updated 1 year ago by
sarawsmn.
- AuthorPosts
- April 26, 2022 at 12:44 pm #33715
sarawsmn
ParticipantHi, we would like to connect the website to the cash-register at the physical store so that all of the orders pass through the register.
Is it possible to get the Lafka theme food-addon values to a functions.php file?
If not, would PPOM work with this theme for addons instead of built-in global addons? https://wordpress.org/plugins/woocommerce-product-addon/
Many thanks,April 27, 2022 at 2:03 pm #33723Althemist
KeymasterHi sarawsmn,
Basically, all the information should be available as the addons are stored as order meta data. I’ll ask our lead developer and CTO Alex to step in and give you more information. Please, allow a bit more time for answer.
April 27, 2022 at 7:07 pm #33732sarawsmn
ParticipantI appreciate that, looking forward to more info…
May 2, 2022 at 6:33 pm #33752Alex
KeymasterHi sarawsmn,
By design the addon data is not meant to be extractable from the order, but I prepared a code you can use to get the addons for a order by given order id. Please note that you have to create an array with your addon labels:
add_action( 'init', function () { $order_id = 5557; // Manually enter all your addon labels $addon_names_list = array( 'Accessories', 'Gift Wrapping', ); /** @var WC_Order $order */ $order = wc_get_order( $order_id ); /** @var []WC_Order_Item $order_items */ $order_items = $order->get_items(); foreach ( $order_items as $order_item ) { /** @var []WC_Meta_Data $order_meta_data */ $order_meta_data_array = $order_item->get_meta_data(); foreach ( $order_meta_data_array as $item ) { foreach ( $addon_names_list as $addon ) { $meta_data = $item->get_data(); if ( strpos( $meta_data['key'], $addon ) !== false ) { echo $meta_data['key'] . ': ' . $meta_data['value']; } } } } } );
On the other hand, you should be able to use another plugin which provides such functionality, but you need to disable the Addons in Lafka from Theme Options -> Shop -> Product Addons
Regards,
AlexMay 3, 2022 at 7:06 pm #33762sarawsmn
ParticipantHi Alex, first of all thank you so much for creating a piece of code especially! This is an interesting approach and it might just solve our issue… we’ll get to work on it 🙂
- AuthorPosts
You must be logged in and have valid license to reply to this topic.