• Resolved mrrosan

    (@mrrosan)


    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

    (@wpscripts)

    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

    (@mrrosan)

    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

    (@wpscripts)

    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

    (@mrrosan)

    Thank you so much, this solved my problem 🙂

    Plugin Author WP Scripts

    (@wpscripts)

    Thanks for the update. Please review the plugin if you find it helpful and like our support.

    Thanks & Regards,
    Team WP Scripts

    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!

    @mrrosan

    Can you send me please how it works for you?
    beacuse i didn’t successed

    Thank you very much.

    Plugin Author WP Scripts

    (@wpscripts)

    Hello @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/.

    Regards,
    Team WP Scripts

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

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