If Else

Closed

Import WP Pro Updated 12 months ago 7 Replies

Jens asked 12 months ago on February 7, 2024 at 8:54 pm

Hi,  please could you help me to create a Code for import field Like this:

[IF({IF(contains({4}, ‘****’]})]OFFERS and PROMOTIONS[ELSE]COUPON CODES & DISCOUNTS[ENDIF]

 It should be changed to: if {4} contains **** then it is OFFERS & PROMOTIONS, otherwise VOUCHER CODES & DISCOUNTS

J

James replied Support Agent

12 months ago on February 8, 2024 at 11:55 am

I have created a custom method that can be used like follows

[iwp_ifelse("{4}", "****", "OFFERS and PROMOTIONS", "COUPON CODES & DISCOUNTS", "contains")]

Custom Method to add to website:

function iwp_ifelse($a = '', $b = '', $return_match = '', $return_nomatch = '', $operator = '=')
{
    $a = trim($a);
    $b = trim($b);

    switch ($operator) {
        case '=':
            return $a == $b ? $return_match : $return_nomatch;
        case '==':
            return $a === $b ? $return_match : $return_nomatch;
        case 'contains':
            return str_contains($a, $b) ? $return_match : $return_nomatch;
        default:
            return $return_nomatch;
            break;
    }
}

 

JG

Jens replied

12 months ago on February 8, 2024 at 4:23 pm

Thanks. So i can Change Code to following Situation, too?

 

[iwp_ifelse("{4}", "****", "OFFERS and PROMOTIONS", "COUPON CODES & DISCOUNTS", "contains")]

If {4} ist empty or has **** it should be empty. If {4} has an entry so import the entry.

It should Look for vouchercode. So If (4) vouchercode is empty or has **** it should be empty If IT has an correct vouchercode IT should import the Code.

J

James replied Support Agent

12 months ago on February 8, 2024 at 4:31 pm

[iwp_ifelse("{4}", "****", "OFFERS and PROMOTIONS", "COUPON CODES & DISCOUNTS", "contains")]

This function checks to see if {4} contains "****" , if it does it returns the text "OFFERS and PROMOTIONS" otherwise it reutrns "COUPON CODES & DISCOUNTS"

So if i understand correctly you would:

[iwp_ifelse("{4}", "****", "", "{4}", "contains")]

If {4} contains **** then it would return empty, otherwise it will return the value of {4}

JG

Jens replied

12 months ago on February 8, 2024 at 4:39 pm

Hi James, before your Plugin i used WP all import.

So Here it was possible to use the following Code:

[IF({code[1][.='']})]{description}[ELSE]{code}[ENDIF]

 

Without modity Code. Could you Check If its compatible?

So the Code for example:

[IF({code[1][.='']})]{description}[ELSE]{code}[ENDIF]

If Code is empty, ge Description, Else get the Code.

 

So for my Case IT should be:

[IF({4[1][.='']})][ELSE]{4}[ENDIF] or im wrong?

J

James replied Support Agent

12 months ago on February 8, 2024 at 4:46 pm

No, IF ELSE is custom to that importer:

[IF({code[1][.='']})]{description}[ELSE]{code}[ENDIF]

You could use the previous custom method (this would be if {4} equals "" then return the description "{5}" otherwise return {4}:

[iwp_ifelse("{4}", "", "{5}", "{4}", "=")]
JG

Jens replied

12 months ago on February 8, 2024 at 4:59 pm

Okay, thanks for clear the Situation.

Please could you explain, how i can Change Code for feature Imports?

 

So example:

I need an shirt Code:

If {4} is empty leave the filed empty, elase get {4}.

Or

If {4} is empty and has No "****" leave the filed empty, elase get {4}.

 

Could you explain how i can ready and Change the Code?

J

James replied Support Agent

12 months ago on February 8, 2024 at 9:33 pm

Currently this custom method has 5 arguments shown below.

[iwp_ifelse("1", "2", "3", "4", "5")]

Arg 1 - This is the left hand side of the comparison

Arg 2 - This is the right hand side of the comparison

Arg 3 - If Argument 1 and 2 match the condition, this value will be returned

Arg 4 - If Argument 1 and 2 do not match the condition, this value will be returend.

Arg 5 is the condition, currently this can be either "=" or "contains" (the function can be modified to include more conditions if required)

If Arg 5 is set to "=" then it will be if Arg 1 matches Arg 2 then arg 3 will be returned otherwise Arg 4 will be returned.  

If Arg 5 is set to "contains" , then it will be if Arg 1 contains Arg 2 then arg 3 will be returned otherwise Arg 4 will be returned.

So based on your 2 examples:

A) If {4} is empty leave the filed empty, elase get {4}. (this is not required because you would not need the method to achieve this, you would just use {4}), for the example tho:

[iwp_ifelse("{4}", "", "", "{4}", "=")]

B) If {4} is empty and has No "****" leave the filed empty, elase get {4}.

[iwp_ifelse("{4}", "****", "{4}", "", "contains")]

 

You can test this in any importer field as once you type the value the preview should update to show the result e.g.:

[iwp_ifelse("ASD****123", "****", "ASD****123", "", "contains")]