sophied73
sophied73

Reputation: 31

How to stop Woocommerce Add to Cart redirecting to Product Pages

Because of a way a customer wanted their products displayed I've used woocommerce shortcode to display products. When Add to Cart is clicked, I didn't want the customer to leave the page but stay on that page until they'd finished ordering.

I have used this code in my Child Theme functions.php file and it successfully stopped the redirection and kept the customer on the page they were on.

//Prevent shortcode [product_page] redirecting to the actual product's page after add to cart
add_filter( 'woocommerce_add_to_cart_redirect', 'wp_get_referer' );

BUT after I added a plugin that gave minimum or maximum quantities and the quantity is below the minimum the Add to Cart redirects to the product page again whenever a product is below the minimum.

I'm not great on php and am not sure what I need to put in the functions.php file to stop this happening.

Any suggestions much appreciated.

Upvotes: 3

Views: 5972

Answers (1)

TurtleTread
TurtleTread

Reputation: 1314

Maybe other plugins are adding filter to the cart redirect as well. You could try to set your own filter's priority to a big number so that it's executed after the other filters.

add_filter('','',50); //or even a bigger number

Upvotes: 1

Related Questions