-1, 'orderby' => 'date', 'order' => 'DESC', 'customer_id' => $user_id, ) ); if ( $orders ) { // Get the latest order for the user. $latest_order = current( $orders ); // Calculate the time difference between the current time and the latest order's creation time. $time_difference = time() - strtotime( $latest_order->get_date_created()->date_i18n( 'Y-m-d H:i:s' ) ); // Calculate the remaining time until the user can place another order (maximum one order per hour). $remaining_time = 60 - round( $time_difference / 60 ); // Convert seconds to minutes. // If the user has placed an order within the last hour, display the notice. if ( $time_difference < 3600 ) { echo '
'; printf( __( 'You can only place one order per hour. Please try again in %d minute(s).', 'woocommerce' ), $remaining_time ); echo '
'; // Disable "Add to Cart" buttons on product pages to prevent additional orders. add_filter( 'woocommerce_is_purchasable', '__return_false' ); } } } // Hook the function to display the restriction notice and disable "Add to Cart" buttons on product pages. // The priority (5) ensures this code runs early before other elements on the product page. add_action( 'woocommerce_before_single_product_summary', 'restrict_orders_per_hour_product_notice', 5 );