2

I've been looking at this for a bit, so maybe my eyes are just fried right now, but I can't seem to figure out why the following conditional is not working:

{if {total_items} != "0"}  
                        <div class="paddingleft36">
                            {if {exp:cartthrob:cart_subtotal prefix=""} >= "40"}
                                <div>Delivery Options<br />
                                <input type="radio" name="delivery_option" value="pickup">Pickup<br>
                                <input type="radio" name="delivery_option" value="delivery">Deliver to:
                                </div>
                            {if:else}
                                {exp:channel:entries channel="cart"}
                                <div>{pickup_only_notice}</div>
                                <div class="cart_options topminus">{delivery_minimum_notice}
                                </div>
                                {/exp:channel:entries}
                            {/if}
                        </div>
                    {/if}

Right now, it just spits out the {if:else} portion of the code, even if the shopping cart subtotal is greater than or equal to ( >= ) 40. When the subtotal is over 40, the Delivery Options radio boxes should appear, but they don't.

This is very confusing and I assume that it might have something to do with the {exp:cartthrob:cart_subtotal prefix=""} tag, but this is precisely how the CartThrob documentation suggests creating conditionals with the cart subtotal (e.g. stripping the currency prefix ($) to compare values.

2 Answers 2

2

Try wrapping that cart_subtotal tag in quotes inside your conditional.

I just tried this out and it worked for me:

{if '{exp:cartthrob:cart_subtotal prefix=""}' >= '40'}
    Delivery Options Code
{if:else}
    This is the else statement
{/if}

This worked with subtotals containing decimal values and also worked if I specified a number with a decimal as the compare value.

Not sure if prefix="no" was just a mistype, but by adding prefix="no" you're going to end up with something like "no30" as the subtotal value you're trying to compare. I think that will always evaluate as greater than 40.

1

I came to the solution for this about 10 minutes after I drafted this question, so I thought I'd share it with anyone who might be stuck on this one. It's simple, but might save some time and hair-pulling.

It turns out the "decimals" parameter in CartThrob's {exp:cartthrob:cart_subtotal} tag must be set to "0" to properly compare its value with another number (even if that other number also contains a decimal). This seems illogical, but it's the way works.

Works properly:

{if {exp:cartthrob:cart_subtotal prefix="no" decimals="0"}[/code] >= "40"}
{if:else}
{/if}

Does not work properly:

{if {exp:cartthrob:cart_subtotal prefix="no"}[/code] >= "40"}
{if:else}
{/if}

Maybe a newbie solution, but a solution nonetheless. :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.