Ecommerce Shopify WordPress Discussion

How to add a new condition (if) to the back button?

I use WordPress. I try to add a new condition (if) to the back button in a plugin file. The back button codes are in the render.php file. this file codes here: https://gist.github.com/paulvek/b24a632b712414c66474d9e04cdf3800 I think need to change these lines: $back_url = ''; if (!$modal) { if (isset($_REQUEST['back'])) { $back_url = "//" . $_SERVER['HTTP_HOST']; } else { $back_url = "//" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $back_url = remove_query_arg(array('login', 'type'), $back_url); } $back_title = __('Go Back'); } So I changed these lines to the code I wrote below (but it doesn't work): if (!$modal) { if (isset($_REQUEST['back'])) { // Check if the user came from the checkout page $referer = wp_get_referer(); $is_from_checkout = strpos($referer, '/checkout/') !== false; if ($is_from_checkout) { $back_url = "https://example.com/cart"; } else { $back_url = "//" . $_SERVER['HTTP_HOST']; } $back_title = __('Go Back'); } else { $back_url = "//" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $back_url = remove_query_arg(array('login', 'type'), $back_url); $back_title = __('Go Back'); } } Can you check these codes and make the necessary changes, please? maybe this helps you with the answer This URL is for when the user comes from the checkout page to the login page https://example.com/checkout/?login=true&page=1&redirect_to=https://example.com/checkout/ I want it when it is ready from here. The back button should redirect the user not to the same page but to the card page, otherwise, the same previous conditions as in the code will be executed. It means to be returned to the same page from which it came. Also maybe this help you with the answer. I use this function to redirect users from the checkout page to the login page. //If in basket click on proceed to checkout and if the user is not logged in, redirect him to the login page before checkout, and after login automatically redirect to checkout for next shopping and not back to the basket add_action('template_redirect', 'check_if_logged_in'); function check_if_logged_in() { if ( ! is_user_logged_in() && is_checkout() ) { $url = site_url('/checkout/?login=true&page=1&redirect_to=https://example.com/checkout/'); wp_redirect( $url ); exit; } } That's why the back button doesn't work there. And for this reason, I want there to be a condition, that if it comes from the checkout page to the login page, the URL will return, not to the same page, but to the cart page. else, return to the same page.
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.