Add "Continue Shopping" button to empty cart

  • Posts: 56
  • Thank you received: 0
11 years 4 months ago #116145

I want to add a "Continue Shopping" button that displays in my cart if the cart is empty. Otherwise, if there is something in the cart, I want the "Continue Shopping" button to be replaced by the "Proceed to Checkout" button.

I have already added the following code to the product / cart.php view, but it shows the "Continue Shopping" button all the time:

   <?php
    $config =& hikashop_config();
$continueShopping = $config->get('continue_shopping', '');
if(!empty($continueShopping)) {
  global $Itemid;
  $url_itemid='';
  if(!empty($Itemid)){
    $url_itemid='&Itemid='.$Itemid;
  }
  if(strpos($continueShopping,'Itemid') === false) {
    if(strpos($continueShopping,'index.php?') !== false) {
      $continueShopping .= $url_itemid;
    }
  }
  if(!preg_match('#^https?://#',$continueShopping)) $continueShopping = JURI::base().ltrim($continueShopping,'/');
  echo $this->cart->displayButton(JText::_('CONTINUE_SHOPPING'),'continue_shopping',$this->params,JRoute::_($continueShopping),'window.location=\''.JRoute::_($continueShopping).'\';return false;','id="hikashop_checkout_shopping_button"');
}
  ?>

Last edit: 11 years 4 months ago by Lutya.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
11 years 4 months ago #116168

Hi,

I think that you should probably test if you have something in your cart or not, something like this will maybe do the job (through the cart file of the product view of your front-end template) :

$cartQty=0;    
foreach($this->rows as $i => $row){
        $cartQty+=$row->cart_product_quantity;
      }
if($cartQty == 0){
//DISPLAY YOUR CONTINUE SHOPPING BUTTON
}

The following user(s) said Thank You: Lutya

Please Log in or Create an account to join the conversation.

  • Posts: 56
  • Thank you received: 0
11 years 4 months ago #116306

That worked! Thank you! In case anyone wants to do this, I added this code to the product / cart.php view:

<?php
  $cartQty=0;    
foreach($this->rows as $i => $row){
        $cartQty+=$row->cart_product_quantity;
      }
if($cartQty == 0){
    $config =& hikashop_config();
$continueShopping = $config->get('continue_shopping', '');
if(!empty($continueShopping)) {
  global $Itemid;
  $url_itemid='';
  if(!empty($Itemid)){
    $url_itemid='&Itemid='.$Itemid;
  }
  if(strpos($continueShopping,'Itemid') === false) {
    if(strpos($continueShopping,'index.php?') !== false) {
      $continueShopping .= $url_itemid;
    }
  }
  if(!preg_match('#^https?://#',$continueShopping)) $continueShopping = JURI::base().ltrim($continueShopping,'/');
  echo $this->cart->displayButton(JText::_('CONTINUE_SHOPPING'),'continue_shopping',$this->params,JRoute::_($continueShopping),'window.location=\''.JRoute::_($continueShopping).'\';return false;','id="hikashop_checkout_shopping_button"');
}
  }
  ?>

Just before the final piece of code:
</div>
<div class="clear_both"></div>
<?php } ?>
<?php
if(JRequest::getWord('tmpl','')=='component'){
  if(!headers_sent()){
    header('Content-Type: text/css; charset=utf-8');
  }
  exit;
}

Please Log in or Create an account to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum