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:
- [Code] show gallery sản phẩm ra trang danh mục của woocommerce
- Lỗi không hiển thị Favicon website wordpress trên chrome và cách xử lý
- Hướng dẫn quét virus cho file hoặc thư mục bằng Windows Security
- Ẩn các sản phẩm không muốn hiển thị trong trang danh mục woocommerce
- Những mẹo sử dụng máy tính hiệu quả