Wicara
Wicara

Reputation: 69

Redirect to the same page after add to cart is clicked

not sure if this is the best option but I would like not to leave the page that the add to cart button is on. In order for more items to be added, I would like to add to cart and stay on the same page. I run into problems with variable products when I add to cart.

I have added some code to the functions php to send the person back to the referring site not sure if this is the best way to do this.

//redirect to the same page
  /**
 * Set a custom add to cart URL to redirect to
 * @return string
 */
function custom_add_to_cart_redirect() { 
    return (wp_get_referer() ); 
}
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );

expected to stay on the same page when adding to cart button is clicked with simple and variable products. I also would like to have the notice shown on the same page.

Upvotes: 0

Views: 1453

Answers (1)

Anil Kumar
Anil Kumar

Reputation: 84

Try this

$referer = $_SERVER['HTTP_REFERER'];
header("Location: $referer");

Upvotes: 1

Related Questions