简体   繁体   中英

Woocommerce redirect to checkout page

I am trying to redirect to the checkout page after i check the quantity of total number of item in the cart. Given the condition if product is equal to 6 it should try to redirect to the checkout page. I tried the below code but cant get it running or need some curl.

function redirectcheck($url){
$tots = WC()->cart->cart_contents_count();

if($tots > 2){
header("Location: http://somepage.php", 
 true, 301);
 exit();
}
}

Maybe it can be a good start...

function check_quantity( $total, $cart ) {
    if( $cart->cart_contents_count = 6 ) {
            $url = get_permalink( get_option( 'woocommerce_checkout_page_id' ) );
    }
    return $url;
}
add_filter( 'woocommerce_calculated_total', 'check_quantity', 10, 2 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM