From 45c44f34064201e800af6234ad5db8fadcd2a54c Mon Sep 17 00:00:00 2001 From: magepeopleteam Date: Tue, 14 Sep 2021 03:32:06 +0000 Subject: [PATCH] function update --- inc/mep_extra_price.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/inc/mep_extra_price.php b/inc/mep_extra_price.php index 45a318d..da3743c 100644 --- a/inc/mep_extra_price.php +++ b/inc/mep_extra_price.php @@ -7,12 +7,27 @@ if (!defined('ABSPATH')) { * This File is a very important file, Because Its gettings Data from user selection on event details page, and prepare the data send to cart item and lastly save into order table after checkout */ +function mep_basic_before_cart_add_validation($passed) +{ + $wc_product_id = isset($_REQUEST['add-to-cart']) ? strip_tags($_REQUEST['add-to-cart']) : ''; + $product_id = isset($_REQUEST['add-to-cart']) ? strip_tags($_REQUEST['add-to-cart']) : ''; + $linked_event_id = get_post_meta($product_id, 'link_mep_event', true) ? get_post_meta($product_id, 'link_mep_event', true) : $product_id; + $product_id = mep_product_exists($linked_event_id) ? $linked_event_id : $product_id; + $event_id = $product_id; + if (get_post_type($event_id) == 'mep_events') { + $not_in_the_cart = apply_filters('mep_check_product_into_cart',true,$wc_product_id); + if (!$not_in_the_cart) { + wc_add_notice("Sorry, This Event already added into the cart. Please First remove this event from the cart to add it again.", 'error'); + $passed = false; + } + } + - - - + return $passed; +} +add_filter('woocommerce_add_to_cart_validation', 'mep_basic_before_cart_add_validation', 10, 90); /**