[WORDPRESS] WooCommerce의 시간 제한을 통해 고객 당 주문 수를 제한하는 방법
WORDPRESSWooCommerce의 시간 제한을 통해 고객 당 주문 수를 제한하는 방법
해결법
-
1.
function new_order_allowed() { // Only on cart and check out pages if( ! ( is_cart() || is_checkout() ) ) return; // Will only work for logged in users if ( is_user_logged_in() ) { // Get user id $user_id = get_current_user_id(); // Get last order $last_order = wc_get_customer_last_order( $user_id ); if ( $last_order ) { // Get date last order created - Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) $date_created = $last_order->get_date_created()->format( 'U' ); // Get current date - Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) $current_time = current_time( 'U', true ); // 24hr in seconds $day_in_sec = 60 * 60 * 24; // Seconds have passed since the last order $seconds_passed = $current_time - $date_created; // Check if ( $seconds_passed < $day_in_sec ) { // Add notice wc_add_notice( sprintf( 'New orders are only allowed %1$s seconds after your previous order, currently %2$s seconds are passed', $day_in_sec, $seconds_passed ), 'error' ); // Removing the Proceed to checkout button from the Cart page remove_action( 'woocommerce_proceed_to_checkout','woocommerce_button_proceed_to_checkout', 20); } } } } add_action( 'woocommerce_check_cart_items', 'new_order_allowed' );
from https://stackoverflow.com/questions/61187979/how-to-limit-the-number-of-orders-per-customer-via-a-time-limit-in-woocommerce by cc-by-sa and MIT license
'WORDPRESS' 카테고리의 다른 글
[WORDPRESS] PHP7.1 치명적인 오류 : [] 연산자는 문자열에 지원되지 않음 [중복] (0) | 2020.11.24 |
---|---|
[WORDPRESS] 고객에게 WooCommerce 구독 취소 이메일 (0) | 2020.11.24 |
[WORDPRESS] WP_LIST_PAGES ($ args)를 포장하는 방법; DIV 및 UL 요소가 있습니까? (0) | 2020.11.24 |
[WORDPRESS] WordPress 테마의 옵션 트리가있는 모든 활판 인쇄 옵션을 추가하는 방법은 무엇입니까? (0) | 2020.11.24 |
[WORDPRESS] Woocommerce 플러그인을위한 보안 문자 reCAPTCHA와 함께 작동하지 않는 WOOCOMMMERCE 체크 아웃 (0) | 2020.11.24 |