• Hi,
    Is there a way to get arrays for “Others” just like “Coupons” or “Products” in JSON?

    Regards,

    Pierre

Viewing 1 replies (of 1 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi Pierre

    Could you test this code ?
    thanks, Alex

    
    add_filter( "woe_json_output_filter", function($json, $record, $formatter){
    	$record['others'] =  woe_get_order_others(WC_Order_Export_Engine::$order_id); // EDIT key 
    	if ( $formatter->mode == 'preview' ) 
    		$flags = JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ;
    	else
    		$flags = JSON_UNESCAPED_SLASHES;
    	return json_encode($record,$flags);	
    },10,3);
    
    function woe_get_order_others($order_id) {
    	global $wpdb;
    	$results = array();
    	$types = array( 'fee'=>'_fee_amount', 'shipping'=>'cost', 'tax'=>'tax_amount');
    	
    	foreach($types as $type=>$key) {
    		$items = $wpdb->get_results("SELECT items.order_item_name, itemmeta.meta_value FROM {$wpdb->prefix}woocommerce_order_items items
    				INNER JOIN  {$wpdb->prefix}woocommerce_order_itemmeta itemmeta
    				ON items.order_item_id = itemmeta.order_item_id AND itemmeta.meta_key = '$key'
    				WHERE items.order_id = $order_id  AND items.order_item_type = '$type'"
    				);
    		foreach($items as $item)		
    			$results[ $item->order_item_name ] = $item->meta_value;
    	}	
    	return $results;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Convert array in JSON’ is closed to new replies.