How to skip cart page on woocomerce for certain products only?

后端 未结 3 1155
忘掉有多难
忘掉有多难 2021-01-19 07:16

I added this to my functions.php file :

add_filter (\'woocommerce_add_to_cart_redirect\', \'woo_redirect_to_checkout\');
function woo_redirect_to_checkout()          


        
3条回答
  •  天命终不由人
    2021-01-19 08:10

    There are a few action hooks as well that you can use, for eg: woocommerce_add_to_cart which passes the product id to the callback function:

    add_action( 'woocommerce_add_to_cart', 'custom_add_to_cart', 10, 2 );
    
    function custom_add_to_cart( $cart_item_key, $product_id ) {
        // replace 123 with a valid product id
        if( 123 == $product_id ) {
            wp_redirect( WC()->cart->get_checkout_url() );
            exit;   
        }
    }
    

提交回复
热议问题