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:
- Các đơn vị đo độ dài trong Css: px, mm, cm, em, rem …
- 5 phần mềm khôi phục dữ liệu trả phí tốt nhất cho Windows
- [Sưu tầm] 20 nguyên tắc thiết kế giúp website của bạn thêm phần chuyên nghiệp
- Chỉnh trang code – Code Beautifier
- Table responsive cho các thiết bị mobile table, thay thế table cho flatsome