Title: Number addition
Last modified: November 26, 2020

---

# Number addition

 *  Resolved [coatsy35](https://wordpress.org/support/users/coatsy35/)
 * (@coatsy35)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/number-addition/)
 * Hi,
 * How would I code a function to perform addition? i.e. {Item Tax}+{Item Cost}=?
   This would be on a custom export XML as I need the including tax price of each
   item for the export file.
 * i.e. Item cost £11.95 + Item Tax £2.39 = £14.34
 * Thanks in advance

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

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/number-addition/#post-13728054)
 * Hi [@coatsy35](https://wordpress.org/support/users/coatsy35/),
 * > How would I code a function to perform addition? i.e. {Item Tax}+{Item Cost}
   > = ?
 * You can do that with a custom PHP function in the export: [https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/](https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/).
   Here’s an untested example snippet that you can modify as needed:
 *     ```
       function my_calculate_prices( $cost, $tax ) {
       	$return = array();
       	if ( is_array( $cost ) && is_array( $tax ) ) {
       		foreach ( $cost as $key => $price ) {
       			$price = str_replace( ",", "", $price );
       			$taxes = str_replace( ",", "", $tax[ $key ] );
       			$return[] = round( $price + $taxes, 2 );
       		}
       		return $return;
       	} else {
       		$price = str_replace( ",", "", $cost );
       		$taxes = str_replace( ",", "", $tax );
       		return round( $price + $taxes, 2 );
       	}
       }
       ```
   
 *  Thread Starter [coatsy35](https://wordpress.org/support/users/coatsy35/)
 * (@coatsy35)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/number-addition/#post-13768219)
 * The array part of that function doesn’t work and I’m struggling to see what is
   wrong? where there are single items it’s fine so the “Else” part is working ok.
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/number-addition/#post-13809938)
 * Hey [@coatsy35](https://wordpress.org/support/users/coatsy35/),
 * > The array part of that function doesn’t work and I’m struggling to see what
   > is wrong? where there are single items it’s fine so the “Else” part is working
   > ok.
 * Can you please replicate the issue on a debug site at [http://wpallimport.com/debug](http://wpallimport.com/debug)
   and open a support request at [https://www.wpallimport.com/support/](https://www.wpallimport.com/support/)
   with the details? We won’t be able to write code for this, but we can make sure
   all of the export settings are correct, the expected data is being exported, 
   and that the function is being called correctly.

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

The topic ‘Number addition’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/number-addition/#post-13809938)
 * Status: resolved