Last active
July 7, 2024 14:39
-
-
Save shameemreza/196a30529ffe6ca74174c110f2b2ab79 to your computer and use it in GitHub Desktop.
Set the maximum order limits per day by PayPal payment gateway in WooCommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hook into the 'woocommerce_checkout_process' action | |
add_action( 'woocommerce_checkout_process', 'restrict_gateway_orders_per_day' ); | |
function restrict_gateway_orders_per_day() { | |
// Set the maximum number of orders allowed per day | |
$max_orders_per_day = 20; | |
// Get the current date | |
$current_date = date( 'Y-m-d' ); | |
// Get the total number of orders for the specific gateway on the current date | |
$orders = wc_get_orders( array( | |
'status' => array( 'completed', 'processing' ), // Include only completed and processing orders | |
'date_created' => '>=' . strtotime( $current_date . ' 00:00:00' ), | |
'payment_method'=> 'paypal', // Replace 'paypal' with your desired gateway | |
) ); | |
$order_count = count( $orders ); | |
// If the maximum number of orders has been reached, display an error message | |
if ( $order_count >= $max_orders_per_day ) { | |
wc_add_notice( __( 'Sorry, we have reached the maximum number of orders for today.', 'woocommerce' ), 'error' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment