Trong quá trình tùy chỉnh lại trang giỏ hàng và thanh toán, một số trường hợp chúng ta cần ngăn không cho khách hàng từ trang giỏ hàng sang trang check out
Để ngăn không cho khách hàng qua trang check out giải pháp đơn giản là ta giấu nút qua thanh toán đi bằng các hàm như sau:
1 |
remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 ); |
Hook vào woocommerce theo ví dụ bên dưới
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// hide Process check out for other state function review_order_before_submit_state_message() { // HERE set your state code $state_code = 'CA'; global $woocommerce; if( $selected_state_code = WC()->customer->get_billing_state() ){ $country_code = WC()->customer->get_billing_country(); $state_name = WC()->countries->get_states($country_code)[$state_code]; if( WC()->customer->get_billing_state() === $state_code ){ //$message = "-----|".$woocommerce->cart->total.'|'; //echo '<ul class="woocommerce-alert">'.$message.'</ul>'; remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 ); } } } add_action( 'woocommerce_review_order_before_submit', 'review_order_before_submit_state_message' ); |
Trong ví dụ trên nếu state là CA (California) thì ta sẽ ẩn không cho hiển thị nút chuyển sang trang thanh toán
Bài viết mới:
- 3 bước để tùy biến trang post archive của theme Flatsome
- Các phím tắt cực kì hữu ích trong Word từ phiên bản 2007, 2010, 2013, 2016 đến 2019
- [Yandex email – 3] Đăng nhập Email Domain miễn phí của Yandex
- Truy xuất thông tin giỏ hàng từ đối tượng $cart trong woocommerce
- 5 Thói quen xấu sẽ làm laptop của bạn mau hư