Jump to content

IF statment if any of the product price is 0 in cart


Mian Waqas

Recommended Posts

Hi,

If i have 2 or more products in cart, and one of them have 0 price and i want to create/remove a button if any of the product price in cart is 0. how i can write the if/else statement? 

this wont work in ajax shopping cart or cart page {if $cart.product.price_amount eq "$ 0"} because it get the value from product page and not from the cart page.
 

Regards 

Link to comment
Share on other sites

{assign var="flag" value=false}
{foreach from=$cart.products item="product"}
    {if $product.price_amount eq "$ 0"}
        {assign var="flag" value=true}
    {/if}
{/foreach}

{if $flag}
    abc
{else}
    xyz
{/if}

Here is how you can achieve this, in case any one needs this in future. 

This code sets the flag variable to false at the beginning. Then it loops through each product in the cart and checks if the product price is $0. If it is, then the flag variable is set to true. After the loop, the code checks the value of the flag variable. If it is true, then it displays "abc". Otherwise, it displays "xyz".

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...