Hi @aipok
The Max Orders (Slot) works on the checkout block. However, you have to make sure the page using the checkout block is properly configured as the Checkout page in WooCommerce.
You can check that in WooCommerce -> Settings -> Advanced -> Page setup.
If you want to use the Checkout block on another page (other than the Checkout page defined by WooCommerce), it’s necessary to use the code snippet below:
add_filter(
'orderable_skip_orders_remaining_check',
function( $skip_orders_remaining_check, $available, $type, $timestamp, $time_slot_settings ) {
global $post;
if ( is_checkout() ) {
return $skip_orders_remaining_check;
}
if ( empty( $post ) ) {
return $skip_orders_remaining_check;
}
$has_checkout_shortcode = has_shortcode( $post->post_content ?? '', 'woocommerce_checkout' );
$has_checkout_block = has_block( 'woocommerce/checkout', $post ) || has_block( 'woocommerce/classic-shortcode', $post );
return ! ( $has_checkout_shortcode || $has_checkout_block );
},
10,
5
);
This code snippet checks if the current page has the shortcode [woocommerce_checkout] or the Checkout block. If so, it doesn’t skip the orders remaining check even though the page is not the checkout page defined by WooCommerce.
Thread Starter
aipok
(@aipok)
Hello.
Unfortunately, we didn’t understand each other very well.
I have two checkout pages created (Checkout 1 created by woocommerce. Block checkout) (Checkout 2 – created by me – old version of checkout with shortcode [woocommerce_checkout]).
- Activated Checkout 1. (block)
Woocommerce – Settings – Advanced – Checkout Page — Selected Block Checkout 1.
The number of orders per time period is set to 15 min. max 1 order.
Two browsers are opened. I enter an order in the first browser, for example, 15:00 and submit the order.
I open the second browser and enter another order and the time 15:00 is still available. It should be 15:15.
THIS IS WRONG!!!
Checkout 2 set
I switch to the old version of the checkout in Woocommerce settings with the shortcode [woocommerce_checkout])
Woocommerce – Settings – Advanced – Checkout page — Checkout 2 selected.
I enter an order in the first browser for example 15:00 and submit the order.
I open the second browser and enter another order and the time is 15:15 That’s how it should be.
The order time limit works correctly.
Otherwise, I didn’t really understand why I should use the code provided above.
Otherwise, I tried to insert the code you provided into functions.php
In the Woocommerce settings, I gradually saved Checkout 1, tested it. Then Checkout 2, tested it. And everything was unchanged. Everything was as I described above.
Simply, the block checkout does not limit the number of orders per time slot.
Thanks for your help
Hi @aipok
Thanks for the clarification — that helps a lot.
You’re right, the block checkout wasn’t enforcing the time slot limits properly. We’ve made an update to fix this.
Here’s the new code snippet you can try:
add_action(
'woocommerce_store_api_cart_errors',
function($cart_errors) {
global $wpdb, $wp_rest_server;
if ( ! $wp_rest_server || ! $wp_rest_server->is_dispatching() ) {
return;
}
$request_data = json_decode( (string) $wp_rest_server::get_raw_data( '/wc/store/v1/checkout' ), true );
$timestamp = absint( $request_data['extensions']['orderable/order-service-date']['timestamp'] ?? null );
$order_time = sanitize_text_field( $request_data['extensions']['orderable-pro/order-service-time']['time'] ?? null );
$time_slot_id = absint( $request_data['extensions']['orderable-pro/order-service-time']['time-slot-id'] ?? 0 );
if (empty($timestamp) || empty($order_time)) {
return;
}
$max_orders_for_slot = (int) $wpdb->get_var(
$wpdb->prepare(
"
SELECT
max_orders
FROM
{$wpdb->orderable_location_time_slots}
WHERE
time_slot_id = %d
",
$time_slot_id
)
);
if ( empty( $max_orders_for_slot ) ) {
return;
}
$date = new DateTime('now', wp_timezone());
$hours = substr( $order_time, 0, 2 );
$minutes = substr( $order_time, 2, 2 );
$date = new DateTime( 'now', wp_timezone() );
$date->setTimestamp( $timestamp );
$date->setTime( $hours, $minutes );
$service_type = Orderable_Services::get_selected_service(false);
$time_slot_settings['max_orders'] = $max_orders_for_slot;
$orders_remaining_for_time_slot = Orderable_Timings_Pro::get_orders_remaining_for_time_slot( $date->getTimestamp(), $service_type, $time_slot_settings );
if ( ! empty( $orders_remaining_for_time_slot ) ) {
return;
}
$cart_errors->add(
'orderable_pro_order_time_error',
__( 'Sorry, the timeslot you selected is no longer available. Please choose another.', 'orderable-pro' )
);
},
25,
1
);
Thank you!
Thread Starter
aipok
(@aipok)
Hi kennethbryanlim
Unfortunately this procedure is unchanged. The problem still persists.
The code has been placed in the functions.php file in my theme.
I repeated everything as I mentioned above. Cleared the server cache, woocommerce and browser.
The block checkout still does not work as it should.
Everything unchanged.
I really appreciate your efforts. We are still working on the old version of the shortcode checkout.
We will continue to be patient for your amazing work to be successful. And the block checkout will work as expected.
I really appreciate your work.
Best regards
Aipok
P.S. I will continue to eagerly follow this thread and hope for success.
Hi @aipok
I looked into this further and found that it only works when the standard WooCommerce checkout shortcode is used, not the new checkout block. I’ve raised this with our development team again for further review and we’ll keep you updated on any developments.
Thank you!
Thread Starter
aipok
(@aipok)
You are amazing. I will wait for your developers to fix this problem.
I wish you much success and have a nice day.
Aipok
P.S. We will keep this thread open. Thank you
Thread Starter
aipok
(@aipok)
Hello friends.
We haven’t heard from each other for a while. I wanted to ask if there is any news on the block checkout issue?
Thank you for your answer.
Aipok
Hi @aipok
We have no updates at the moment but will follow up with the team.
Once the release is out, we will keep you updated.
Hi @aipok
This issue is fixed in Orderable Pro 1.18.2. Just make sure that the Checkout page is properly set up in WooCommerce (WooCommerce -> Settings -> Advanced -> Page setup).