(Retail test Cart)
add_action('woocommerce_check_cart_items', 'limit_cart_total_for_looged_in_users'); function limit_cart_totaol_for_looged_in_users() { $cart_total = wc()-cart->get_total('edit'); $limit = 5000; if ($cart_total > $limit) { wc_add_notice (' you cannot proceed to checkout. Your cart total exceeds the limit of 5000SAR. ', 'error'); } } } function custom_cart_limit() { $max_quantity = 100; // Set the maximum quantity limit $cart_quantity = WC()->cart->get_cart_contents_count(); if ( $cart_quantity > $max_quantity ) { wc_add_notice( 'You have reached the maximum quantity limit.', 'error' ); return false; } return true; } add_action( 'woocommerce_add_to_cart_validation', 'custom_cart_limit' ); add_action('commerence_check_cart_limnit' , 'limit_cart_total_for_logged_in_users'); add_filter('woocommerce_add_to_cart_validation', 'limit_add_to_cart_based_on_cart_total', 10, 3); function limit_add_to_cart_based_on_cart_total($passed, $product_id, $quantity) { if (is_user_logged_in()) { $cart_total = WC()->cart->get_cart_contents_total(); $limit = 5000; // Get the price of the product being added $product_price = get_post_meta($product_id, '_price', true); $future_total = $cart_total + ($product_price * $quantity); if ($future_total > $limit) { wc_add_notice('You cannot add this item. Cart total would exceed 5000 SAR.', 'error'); return false; } } return $passed; //Get the price back to cart if (user_logged_in(){ $cart_total = WC()-cart->get_cart_contents_total(); $limit = 5000; $product_price = get_post_meta($product_id, '_price' , true); $futute_total = $cart_total + ($product_price * $quantity); if ($future_total > $limit) { wc_add_notice(' You cannot add this item. card total would exceed 5000SAR.', 'error'); return false; } }