Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable add to cart redirection

Now, hitting the "add to chart" button on the archive page will add product to cart, but will also redirect custommer to the page of certain product, and I am trying to disable any redirection after hitting "add to cart" button. I want custommer to stays at the same page where he has been before hitting the button, or just to "refresh" page after adding to cart.

Any suggestions?

/**
 * Redirect subscription add to cart to checkout page
 *
 * @param none
 */
function add_to_cart_checkout_redirect() {
        wp_safe_redirect( get_permalink( get_option(
           'woocommerce_checkout_page_id' ) ) );
        die();
  }
add_action( 'woocommerce_add_to_cart',  'add_to_cart_checkout_redirect', 11
);
like image 649
momciloo Avatar asked Dec 01 '22 17:12

momciloo


2 Answers

WooCommerce Settings

WooCommerce by default provides the setting for you. Just check if this solution fits your requirement.

like image 146
Domain Avatar answered Dec 04 '22 09:12

Domain


Try to use wp_get_referer as shown

add_filter( 'woocommerce_add_to_cart_redirect', 'wp_get_referer' );
like image 34
Fungie Avatar answered Dec 04 '22 10:12

Fungie