May I know whether there is a built-in hook or filter that I can use when an event is added to the cart and then redirected to the checkout page? I want to clear the cart and ensure it is empty before adding the event product.
Flow: Event Booking List → Book Event → Clear Cart (if it is not empty) → Redirect to Checkout Page
I have tried using WooCommerce's woocommerce_add_to_cart_validation filter hook but to no avail. (It is working for regular WooCommerce products.)
function filter_woocommerce_add_to_cart_validation( $passed, $product_id, $quantity, $variation_id = null, $variations = null ) {
if ( WC()->cart->is_empty() ) {
wc_add_notice( __( 'Please enter a value into the text flowers label', 'woocommerce' ), 'error' );
$passed = false; // Mark the validation as failed
}
return $passed;
}
add_filter( 'woocommerce_add_to_cart_validation', 'filter_woocommerce_add_to_cart_validation', 10, 5 );
We just got the feedback from our colleagues and they have told us to send you a fix in the attachment and that they have added a WP action, so you can add this code to functions.php:
function ameliaAddBookingToWcCart($data)
{
$wc = wc()->cart;
foreach ($wc->get_cart() as $wc_key => $wc_item) {
$wc->remove_cart_item($wc_key);
}
}
add_action('AmeliaAddBookingToWcCart', 'ameliaAddBookingToWcCart');
this is triggered before adding our booking to the cart, so this code will empty the cart first.
You are most welcome, and we are glad that we were able to help you. Should you have any further inquiries, we kindly request that you open separate tickets for each question and we will gladly help you there.
Hi there,
May I know whether there is a built-in hook or filter that I can use when an event is added to the cart and then redirected to the checkout page? I want to clear the cart and ensure it is empty before adding the event product.
Flow: Event Booking List → Book Event → Clear Cart (if it is not empty) → Redirect to Checkout Page
I have tried using WooCommerce's woocommerce_add_to_cart_validation filter hook but to no avail. (It is working for regular WooCommerce products.)
Hello Patrick,
We have forwarded your ticket to our level 2 agents and as soon as we get some feedback from them we will contact you immediately.
Kind Regards,
Marko Davidovic [email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps, floor plans, choropleth maps, and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hello Patrick,
We just got the feedback from our colleagues and they have told us to send you a fix in the attachment and that they have added a WP action, so you can add this code to functions.php:
this is triggered before adding our booking to the cart, so this code will empty the cart first.
Hope this helps.
Attached files: src (1).zip
Kind Regards,
Marko Davidovic [email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps, floor plans, choropleth maps, and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Thank you so much for your help and the code snippets!
Hello Patrick,
You are most welcome, and we are glad that we were able to help you. Should you have any further inquiries, we kindly request that you open separate tickets for each question and we will gladly help you there.
We wish you all the best.
Have a nice day.
Kind Regards,
Marko Davidovic [email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps, floor plans, choropleth maps, and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables