Title: Add-ons problem
Last modified: March 25, 2021

---

# Add-ons problem

 *  Resolved [mrrosan](https://wordpress.org/support/users/mrrosan/)
 * (@mrrosan)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/add-ons-problem/)
 * Hello, I am coding a template to print the orders directly and automatically.
   
   How can I get those add-ons right. Here is my code:
 *     ```
       <?php foreach ($order->get_items() as $item) {
       	/* @var $item \WC_Order_item */
       	$meta = $item['item_meta'];
       	$meta = array_filter($meta, function ($key) {
       		return !in_array($key, Order::getHiddenKeys());
       	}, ARRAY_FILTER_USE_KEY);
       	?>
       	<?= Document::symbolsAlign($item['name'] . ' &times; ' . $item['qty'], wc_price($item->get_data()['total'], array('currency' => $order->get_currency()))); ?>
       	<?php $meta = array_map(function ($meta, $key) {
       		return Document::symbolsAlign(' ' . $key, $meta . ' ');
       	}, $meta, array_keys($meta));
       	echo implode('', $meta);
       	?>
       <?php } ?>
       ```
   
 * Here is the result:
    Veg. Keema Masala × 1 €14,95 _addon_items Array

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [WP Scripts](https://wordpress.org/support/users/wpscripts/)
 * (@wpscripts)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/add-ons-problem/#post-14237010)
 * Hello,
 * You can use the function `wfs_get_addons_from_meta` with only parameter $item_id
   to get all details regarding the addon. As I can see you already have the $item
   array, you just need to pass the $item_id to this function.
 * In another way, you can check above mentioned function and follow the code written
   there. You can find the file at food-store/includes/wfs-core-functions.php.
 * Hope this helps.
 * Regards,
    Team WP Scripts
 *  Thread Starter [mrrosan](https://wordpress.org/support/users/mrrosan/)
 * (@mrrosan)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/add-ons-problem/#post-14238033)
 * Hello, I tried but no result :/
    Can you please tell me which part of my code
   should be changed? Thank you in advance
 *  Plugin Author [WP Scripts](https://wordpress.org/support/users/wpscripts/)
 * (@wpscripts)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/add-ons-problem/#post-14238059)
 * Hello,
 * You have the $item array/object already. Considering that you can get the item
   ID by `$item['item_id']`.
 * With this ID as parameter you have to call the function mentioned above and you
   shall get the list of addons with name and price. Plugin itself working using
   that plugin. Unless it is debugged we can’t tell where you are making the mistake.
   Hope you understand this.
 * Regards
 *  Thread Starter [mrrosan](https://wordpress.org/support/users/mrrosan/)
 * (@mrrosan)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/add-ons-problem/#post-14238325)
 * Thank you so much, this solved my problem 🙂
 *  Plugin Author [WP Scripts](https://wordpress.org/support/users/wpscripts/)
 * (@wpscripts)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/add-ons-problem/#post-14238333)
 * Thanks for the update. Please [review](https://wordpress.org/support/plugin/food-store/reviews/#new-post)
   the plugin if you find it helpful and like our support.
 * Thanks & Regards,
    Team WP Scripts
 *  [tomercohen84](https://wordpress.org/support/users/tomercohen84/)
 * (@tomercohen84)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/add-ons-problem/#post-14332076)
 * Hello
 * same problem, try your solution but didn’t successed.
    PLEASE HELP!!!
 * this is my code:
 *     ```
       <?php foreach ($order->get_items() as $item) {
       		/* @var $item \WC_Order_item */
       		$meta = $item['item_meta'];
       		$meta = array_filter($meta, function ($key) {
       			return !in_array($key, Order::getHiddenKeys());
       		}, ARRAY_FILTER_USE_KEY);
       		?>
       		<tbody>
       		<tr>
       			<td style="padding-left:10px" rowspan="<?= count($meta) + 1; ?>"><?= wc_price($item->get_data()['total'], array('currency' => $order->get_currency())); ?></td>
       			<td style="text-align:right;padding-right:10px" colspan="2"><?= $item['name']; ?> &times; <?= $item['qty']; ?></td>
   
       		</tr>
       		<?php $meta = array_map(function ($meta, $key) {
       			$result = '<tr>';
       			$result .= '<td>' . $key . '</td>';
       			$result .= '<td>' . $meta . '</td>';
       			$result .= '</tr>';
       			return $result;
       		}, $meta, array_keys($meta));
       		echo implode(PHP_EOL, $meta);
       		?>
       		</tbody>
       ```
   
 * what i need to change to get the addon list with item?
 * Thank you so much!
 *  [tomercohen84](https://wordpress.org/support/users/tomercohen84/)
 * (@tomercohen84)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/add-ons-problem/#post-14364894)
 * [@mrrosan](https://wordpress.org/support/users/mrrosan/)
 * Can you send me please how it works for you?
    beacuse i didn’t successed
 * Thank you very much.
 *  Plugin Author [WP Scripts](https://wordpress.org/support/users/wpscripts/)
 * (@wpscripts)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/add-ons-problem/#post-14365425)
 * Hello [@tomercohen84](https://wordpress.org/support/users/tomercohen84/)
 * Please refer to below code,
 *     ```
       // MAKE SURE YOU HAVE $ITEM OBJECT INSIDE YOUR FUNCTION
   
       $item_id 		= $item['item_id'];
       $addon_items 	= wfs_get_addons_from_meta( $item_id );
   
       $string = '';
   
       if ( ! empty( $addon_items ) && is_array( $addon_items ) ) {
   
       	foreach( $addon_items as $key => $addon_item ) {
   
       		// THIS IS YOUR ADDON NAME
       		$addon_name = isset( $addon_item['name'] ) ? $addon_item['name'] : ”;
   
       		// THIS IS YOUR ADDON PRICE
       		$addon_price = isset( $addon_item['price'] ) ? $addon_item['price'] : ”;
   
       		// MAKE SURE TO ECHO OR GENERATE STRING AT APPROPREATE PLACE
       		echo $addon_name;
       		echo $addon_price;
       	}
       }
   
       $special_note = wc_get_order_item_meta( $item_id, '_special_note', true );
   
       if ( ! empty( $special_note ) ) {
   
       	// THIS IS YOUR SPECIAL NOTE ACCOCIATED WITH THE ITEM
       	echo $special_note;
       }
       ```
   
 * Try to take the pieces as per your need. If you need paid support create a ticket
   at [http://support.wpscripts.in/](http://support.wpscripts.in/).
 * Regards,
    Team WP Scripts

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Add-ons problem’ is closed to new replies.

 * ![](https://ps.w.org/food-store/assets/icon-256x256.png?rev=2323647)
 * [Food Store - Online Food Delivery & Pickup](https://wordpress.org/plugins/food-store/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/food-store/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/food-store/)
 * [Active Topics](https://wordpress.org/support/plugin/food-store/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/food-store/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/food-store/reviews/)

 * 8 replies
 * 3 participants
 * Last reply from: [WP Scripts](https://wordpress.org/support/users/wpscripts/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/add-ons-problem/#post-14365425)
 * Status: resolved