1. Home
  2. Docs
  3. Woocommerce Snippet
  4. 장바구니 생략 + 한가지 상품만 담기

장바구니 생략 + 한가지 상품만 담기

장바구니 버튼 클릭 시 > 결제 페이지로 바로 이동

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

 

기존에 담긴 장바구니 상품들은 제거 후 이동시킬 때

add_filter('woocommerce_add_cart_item_data', 'only_one_product_in_cart');
function only_one_product_in_cart($cart_item_data) {
    global $woocommerce; // WC()-> 형태로도 가능
    if ($woocommerce -> cart -> get_cart_contents_count() != 0) {
        $woocommerce -> cart -> empty_cart();
    }
    return $cart_item_data;
}

※ 부킹스 익스텐션 추가로 상품을 예약용으로만 구성 시 유용한 방법