"woocommerce_get_checkout_url" hook is not working

72 Views Asked by At

` I have created as plugin for wordpress, i have used "woocommerce_get_checkout_url" hook to change checkout button redirection. It is working fine in older versino of wordpress, but not working in wordprss verion 6.4.3 Here is a code.

add_filter( 'woocommerce_get_checkout_url', 'custom_checkout' );
function custom_checkout(){
   if ( isset( $\_SESSION\['ReturnURL'\] ) ){
     return get_home_url() . '/customcheckout';
   } 
   else { 
     return get_home_url() . '/checkout'; 
   } 
}

Anybody can suggest, what can we do for that ? We have also tried:

add_filter( 'woocommerce_get_checkout_url', 'custom_checkout', 30 );

and

add_filter( 'woocommerce_get_checkout_url', 'custom_checkout', 1, 100 );

but it is not working in wordpress 6.4.3

1

There are 1 best solutions below

0
LoicTheAztec On

There are some mistakes in your code, you should try the following instead:

add_filter( 'woocommerce_get_checkout_url', 'custom_checkout', 10, 1 );
function custom_checkout( $checkout_url ){
   if ( isset($_SESSION['ReturnURL']) ){
       $checkout_url = home_url('/customcheckout');
   } 
   return $checkout_url;  
}

Code goes in functions.php file of your child theme (or in a plugin). Tested and works (if the session variable "ReturnURL" exists, the checkout URL is your custom checkout URL).