📜  woocommerce_continue_shopping_redirect - PHP (1)

📅  最后修改于: 2023-12-03 15:21:12.681000             🧑  作者: Mango

woocommerce_continue_shopping_redirect - PHP

The woocommerce_continue_shopping_redirect hook in PHP is used to redirect users back to the previous page after they click on "continue shopping" in the cart.

Usage

To use this hook, first, we need to create a function that returns the URL we want to redirect to. Here's an example:

function my_continue_shopping_redirect() {
    return get_permalink(12); // Replace 12 with the ID of the page you want to redirect to.
}
add_filter('woocommerce_continue_shopping_redirect', 'my_continue_shopping_redirect');

This function will redirect users to the page with ID 12 after they click on "continue shopping" in the cart.

Parameters

The woocommerce_continue_shopping_redirect hook does not require any parameters.

Return Values

The woocommerce_continue_shopping_redirect hook should return a URL string that the user will be redirected to.

Examples
  1. Redirect users to the homepage after clicking "continue shopping"
function my_continue_shopping_redirect() {
    return home_url();
}
add_filter('woocommerce_continue_shopping_redirect', 'my_continue_shopping_redirect');
  1. Redirect users to the previous page they were on after clicking "continue shopping"
function my_continue_shopping_redirect() {
    return wp_get_referer() ? wp_get_referer() : home_url();
}
add_filter('woocommerce_continue_shopping_redirect', 'my_continue_shopping_redirect');
Conclusion

The woocommerce_continue_shopping_redirect hook in PHP is very useful for redirecting users back to the previous page after they click on "continue shopping" in the cart. With this hook, we can easily customize where users will be redirected to.