• Resolved eninunez

    (@eninunez)


    Hello,
    I have this csv with products

    post_id 000.011
    post_title test
    undefined2 4,5
    undefined3 10
    undefined4 4,5
    undefined5 20 // stock
    undefined6 30 // orders from clients
    undefined7 120 // available stock for backorders
    undefined8 111

    I want to make a minus for stock quantity like
    [MATH({undefined5[1]},”-“,{undefined6[1]})] and tha is ok when the result is nevative.
    I dont want the negative number for stock.
    In this case i want to show as stock quantity = 0 and the difference in result to be deducted from available stock for backordes.

    if ( {undefined5[1]} – {undefined6[1]} <=0 )
    {undefined5[1]} = 0;

    else if ( {undefined5[1]} – {undefined6[1]} > 0 )
    {undefined5[1]} = {undefined5[1]} – {undefined6[1]};

    else if ( {undefined5[1]} – {undefined6[1]} <0 )
    {undefined7[1]} = ( {undefined5[1]} – {undefined6[1]} ) + {undefined6[1]} )

    Can i have this result with if statement with syntax like that I saw in another topic?
    “” [IF({promopricec[1][.=”.00″]})][ELSE]{promopricec[1]}[ENDIF] “”

    Or with php function, if you can tell me how to get and define {undefined5[1]}, {undefined6[1]}, {undefined7[1]} in function and how to get the function to fields

    thanks you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @eninunez,

    Or with php function, if you can tell me how to get and define {undefined5[1]}, {undefined6[1]}, {undefined7[1]} in function and how to get the function to fields

    Given the complexity of the calculations, a function would definitely be the way to go. We explain how they work here: https://www.wpallimport.com/documentation/developers/custom-code/inline-php/. As an example, you can pass the elements to your function in the import field like this:

    [my_calc_stock({undefined5[1]},{undefined6[1]},{undefined7[1]})]

    And, in the Function Editor, you’d create the code that does the calculations. Here’s an incomplete example that you can build off of:

    function my_calc_stock( $stock, $orders_from_clients, $backorder_qty ) {
    	if ( $stock - $orders_from_clients < 0 ) {
    		return ( $stock - $orders_from_clients ) + $orders_from_clients;
    	} elseif ( $stock - $orders_from_clients == 0 ) {
    		return 0;
    	} else {
    		return $stock - $orders_from_clients;
    	}
    }
    Thread Starter eninunez

    (@eninunez)

    Thanks. That is exactly what i need.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘If statement with math’ is closed to new replies.