Disable add to cart redirection

2019-07-23 17:40发布

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
);

5条回答
三岁会撩人
2楼-- · 2019-07-23 18:16

Please add the following code to the file functions.php

/**
 * Set a custom add to cart URL to redirect to
 * @return string
 */
function custom_add_to_cart_redirect() { 
    return 'http://www.yourdomain.com/your-page/'; 
}
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );

Thanks

查看更多
ら.Afraid
3楼-- · 2019-07-23 18:17

Use remove action

remove_action( 'woocommerce_add_to_cart',  'add_to_cart_checkout_redirect', 1);
查看更多
Explosion°爆炸
4楼-- · 2019-07-23 18:21

Try to use wp_get_referer as shown

add_filter( 'woocommerce_add_to_cart_redirect', 'wp_get_referer' );
查看更多
Melony?
5楼-- · 2019-07-23 18:22

WooCommerce Settings

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

查看更多
beautiful°
6楼-- · 2019-07-23 18:36

Here is the answer. If you want custom redirection, there is a filter for that:

add_filter( 'woocommerce_add_to_cart_redirect', 'custom_redirect_function' );
    function custom_redirect_function() {
    return get_permalink( wc_get_page_id( 'shop' ) );
}
查看更多
登录 后发表回答