Woocommerce add to cart button redirect to checkout

前端 未结 8 1950
时光取名叫无心
时光取名叫无心 2020-12-05 23:49

I created an ecommerce using the plugin woocommerce. I am selling only a subscription so the \"/cart/\" page is useless. I\'m trying to get rid of it so that when my custome

8条回答
  •  旧巷少年郎
    2020-12-06 00:07

    you can use a filter in functions.php:

    add_filter ('add_to_cart_redirect', 'redirect_to_checkout');
    
    function redirect_to_checkout() {
        global $woocommerce;
        $checkout_url = $woocommerce->cart->get_checkout_url();
        return $checkout_url;
    }
    

    it doesn't seem to work with ajax, but it works from the single product pages, which I think is what you use

    On the latest versions of WooCommerce (>= 2.1) the function can be simplified as:

    function redirect_to_checkout() {
        return WC()->cart->get_checkout_url();
    }
    

提交回复
热议问题