Error when using the if option

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #129273
    blankChristiaan Grob
    Participant

    Hi, I’m using this plugin to send a manual email to my user with there order data based on meta field values.

    Also, in side this email i display a table with options based on meta field values but for some reason i’m getting an error if i use the If option inside an if option. :

    
    <table cellspacing="0" cellpadding="6" border="1" width="100%" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;width: 100%;font-family: 'Helvetica Neue',Helvetica,Roboto,Arial,sans-serif">
    <tfoot>
    
    <tr>
    <th scope="row" colspan="2" align="left" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Via welk platform huurt huurder?</th>
    <td align="left" style="min-width: 60px;color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Peerby</td>
    </tr>
    
    <tr>
    <th scope="row" colspan="2" align="left" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Peerby order #</th>
    <td align="left" style="min-width: 60px;color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">[order_meta key='additional_field_205']</td>
    </tr>
    
    [if value1="{order_meta key='additional_field_501'}" operator="equal" value2="Ja"]
    
    <tr>
    <th scope="row" colspan="2" align="left" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Borg bedrag in EUR</th>
    <td align="left" style="min-width: 60px;color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">[order_meta key='additional_field_563']</td>
    </tr>
    
    [/if]
    
    <tr>
    <th scope="row" colspan="2" align="left" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Huurperiode</th>
    <td align="left" style="min-width: 60px;color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">[order_meta key='additional_field_806']</td>
    </tr>
    
    [if value1="{order_meta key='additional_field_681'}" operator="equal" value2="Nee"]
    
    <tr>
    <th scope="row" colspan="2" align="left" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Afleveren en/of ophalen bij klant?</th>
    <td align="left" style="min-width: 60px;color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Nee</td>
    </tr>
    
    <tr>
    <th scope="row" colspan="2" align="left" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Datum en tijd voor ophalen door klant</th>
    <td align="left" style="min-width: 60px;color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">[order_meta key='additional_field_989']</td>
    </tr>
    
    <tr>
    <th scope="row" colspan="2" align="left" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Datum en tijd voor terugbrengen door klant</th>
    <td align="left" style="min-width: 60px;color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">[order_meta key='additional_field_630']</td>
    </tr>
    
    [if value1="{order_meta key='additional_field_644'}" operator="equal" value2="Locatie_Amsterdam_Amstel"]
    
    <tr>
    <th scope="row" colspan="2" align="left" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Locatie van items</th>
    <td align="left" style="min-width: 60px;color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Locatie Amsterdam Amstel</td>
    </tr>
    
    [/if]
    
    [if value1="{order_meta key='additional_field_644'}" operator="equal" value2="Locatie_Amstelveen"]
    
    <tr>
    <th scope="row" colspan="2" align="left" style="color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Locatie van items</th>
    <td align="left" style="min-width: 60px;color: #636363;border: 1px solid #e5e5e5;vertical-align: middle;padding: 12px;text-align: left;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 1px">Locatie Amstelveen</td>
    </tr>
    
    [/if]
    
    [/if]
    
    </tfoot>
    </table>
    
    

    Everything is working fine but when I’m at the last part of this table then both additional_field_644 > Locatie_Amstel_Amstel and Locatie_Amstelveen are showing up in the mail. And in the email above the table there appears a line with the text: “[/if]“.

    Can you explain me why this is happening? And what can i do about it?

    #129376
    blankChristiaan Grob
    Participant

    Solved it myself. You can not use the if inside the if shortcode but you can do &.

    [if value1="{order_meta key='additional_field_681'}" operator="equal" value2="Nee" & if value1="{order_meta key='additional_field_644'}" operator="equal" value2="Locatie_Amstelveen"]

    So it checks of both conditions are applied at the same time

    #129429
    blankChristiaan Grob
    Participant

    Oh no, I had it wrong, it is not working. It is only checking the first if not the second one, so the & is not working and it is still showing duplicated rows. Would be nice of someone of the support would dive in to this.

    #129976
    blankMoshtafizur
    Moderator
    Plugin Support

    Hi there,

    I am really sorry to know you are experiencing problems.

    I have escalated this with our development team. They will get back to you as soon as they can.

    Kind regards.

    #130450
    blankTom Anbinder
    Moderator
    Plugin Support

    Hi, Christiaan,

    You can neste shortcodes, but not with the same name, so one of the solutions would be to create an alias for the [if] shortcode with a PHP snippet, e.g., [my_if]:

    add_shortcode( 'my_if', function ( $atts, $content = '' ) {
        if ( function_exists( 'alg_wc_custom_emails' ) && isset( alg_wc_custom_emails()->core->shortcodes ) ) {
            return alg_wc_custom_emails()->core->shortcodes->if( $atts, $content );
        }
    } );

    Then you can do this:

    [if][my_if]...[/my_if][/if]

    Please give it a try and let me know what you think.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.