Jump to content

Empty cart button fix


designfront

Recommended Posts

hey guys, got a problem,

 

basically, on the shopping cart it has the three buttons. View products,

> view basket and clear basket, even when the cart is empty a notification

> message will be shown when u click empty basket.

>

> The link of the empty basket is= index.php?clear=1

>

> And it gets processed by:

>

> if (isset($_REQUEST['clear']))

>

> {

> $shopping_cart->EmptyCart();

> echo render_notification('

Shopping Cart

> Emptied

');

> }

>

> And i wanted to add something like on where the actual link is like

>

> function check_if_empty($check_if_empty)){

>

> If (empty($cart)){

>

> $check_if_empty = "";

>

> }else{

>

> $check_if_empty = "

and the link in here";

>

> }

>

> }

>

> And then just replace where the li used to be with the function variable, is

> that a ok solution? But don't know whts wrong with the syntax not working,

>

> Many thanks

> Andre Figueira

Link to comment
Share on other sites

Looks like you are pretty close to having it work... you shouldn't need to place it in a function, just add something like this in the spot in your file where the button will appear:

 

If (empty($cart)){

// if cart is already empty, don't display the button (or take another action -- I'm not sure what you had min mind)

}else{

// cart isn't empty, display the "clear basket" button

}

Link to comment
Share on other sites

Hi all got it working not the best way it can be done i think but it works, i figured the reason it wasnt working is that the cart isnt empty and it isnt the default string length is 45 so i just said count the string length if its more than 45 then show the button and sure enough its working, now to count the total products in cart hehe, code below:

 


function render_empty_cart_btn()//Checks if the cart is empty by counting the string length, if the string length is longer than the default length of 45 then it adds the empty cart button.
{
   $cart = ($_SESSION['cart']);
   if(strlen($cart) > 45)
   {
   echo"Empty Cart



";
   }else{

       echo"



";
   }
}

Edited by designfront
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...