Jump to content
Sign in to follow this  
artaweb

How to redirect cart.php to a custom page

Recommended Posts

Hey Guys,

 

I want by default redirect /cart.php and /cart.php?gid=[number] to /index.php but if a user is placing an order eg: /cart.php?a=add&pid=[number] it should take the user ahead with purchase.

 

I tried using .htaccess but if I redirect /cart.php to a custom page, the rest of links that starts with /cart.php also redirects to that custom page.

 

I appreciate if anyone can help me to figure this out

Thank you

Share this post


Link to post
Share on other sites

create new PHP file inside /includes/hooks/ directory and copy the following code inside it:

 

<?php


add_hook("ClientAreaPage",1,function($vars){
   if ($vars['filename']=="cart" && !isset($_REQUEST['a'])){
       header("Location: index.php");
       exit;
   }
});

Share this post


Link to post
Share on other sites

Thank you so much. This worked perfectly.

Is there any possibility to exclude one specific group id from getting redirected? like /cart.php?gid=8

Share this post


Link to post
Share on other sites

yes, this should work, you can specify more than one group to be excluded from the redirection at line #7

 

<?php


add_hook("ClientAreaPage",1,function($vars){

   # Product Groups Excluded From The Redirection
   $excludedGroups = array(1, 4, 6);

   if ($vars['filename']=="cart" && in_array($_REQUEST['gid'], $excludedGroups)){
       return;
   }

   if ($vars['filename']=="cart" && !isset($_REQUEST['a'])){
       header("Location: index.php");
       exit;
   }
});

Share this post


Link to post
Share on other sites

Hello,

Sorry for bumping this old topic. 

How can the bid for product bundles get excluded from this code? (cart.php?a=add&bid=2) I am making a product bundle and its getting redirected to homepage. 

THis is my current code:

<?php


add_hook("ClientAreaPage",1,function($vars){
    if (!empty($_GET['cartshare'])) {
        return;
    }

    # Product Groups Excluded From The Redirection
    $excludedGroups = array(8, 10, 11, 12, 13, 15, 6, addons, renewals);

    if ($vars['filename']=="cart" && in_array($_REQUEST['gid'], $excludedGroups)){
        return;
    }

    if ($vars['filename']=="cart" && !isset($_REQUEST['a'])){
        header("Location: index.php");
        exit;
    }
});

 

Share this post


Link to post
Share on other sites
4 hours ago, artaweb said:

How can the bid for product bundles get excluded from this code? (cart.php?a=add&bid=2) I am making a product bundle and its getting redirected to homepage. 

 

the same way we exclude product group, try the following:

<?php


add_hook("ClientAreaPage",1,function($vars){
    if (!empty($_GET['cartshare'])) {
        return;
    }

    # Product Groups Excluded From The Redirection
    $excludedGroups = array(8, 10, 11, 12, 13, 15, 6, addons, renewals);
    
    # Product Bundles Excluded From The Redirection
    $excludedBundles = array(2);

  	# Validate Product Groups
    if ($vars['filename']=="cart" && in_array($_REQUEST['gid'], $excludedGroups)){
        return;
    }
  	
    # Validate Product Bundles
    if ($vars['filename']=="cart" && in_array($_REQUEST['bid'], $excludedBundles)){
        return;
    }

    if ($vars['filename']=="cart" && !isset($_REQUEST['a'])){
        header("Location: index.php");
        exit;
    }
});

 

Share this post


Link to post
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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated