artaweb Posted January 12, 2017 Share Posted January 12, 2017 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 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted January 13, 2017 Share Posted January 13, 2017 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; } }); 0 Quote Link to comment Share on other sites More sharing options...
artaweb Posted January 13, 2017 Author Share Posted January 13, 2017 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 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted January 14, 2017 Share Posted January 14, 2017 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; } }); 0 Quote Link to comment Share on other sites More sharing options...
artaweb Posted January 14, 2017 Author Share Posted January 14, 2017 Thank you so much for sharing your knowledge with me. I really appreciate it. 0 Quote Link to comment Share on other sites More sharing options...
artaweb Posted June 28, 2020 Author Share Posted June 28, 2020 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; } }); 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted June 28, 2020 Share Posted June 28, 2020 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; } }); 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.