• Resolved coatsy35

    (@coatsy35)


    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

    (@wpallimport)

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

    (@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.

    Plugin Author WP All Import

    (@wpallimport)

    Hey @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 https://wpallimport.com/debug and open a support request at 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.