AI Verified

Name

Limit the possible items in the shopping cart

About

In certain cases it may make sense to reduce the possible products in the shopping cart to "1". For example, if you sell a subscription product. You can do that quickly and easily with this WooCommerce snippet.

Language

PHP

Rating

Voted: 1 by 1 user(s)

Codevault

jbeer

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

03/02/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Limit the possible items in the shopping cart

 
                    
1if (!function_exists( 'evolution_only_one_product_in_cart' ) ) :
2/**
3* @snippet WooCommerce maximal 1 Produkt im Warenkorb
4*/
5function evolution_only_one_product_in_cart( $passed, $added_product_id ) {
6 
7 wc_empty_cart();
8 return $passed;
9 
10}
11add_filter( 'woocommerce_add_to_cart_validation', 'evolution_only_one_product_in_cart', 99, 2 );
12endif;

1

Comments

  • AR

    1 year ago

    Hey nice snippet, can you add a snippet that will limit the total number of items in a cart to a specified number like 3 etc.?

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

WooCommerce Change “Choose Some Product Options” Text

Added: 1 year ago

Last Updated: 1 year ago

A lot of the time, users will miss the attribute drop down on a variable product page and immediately go for the add to cart button. If this happens, and the user has not yet selected an option from t...

WooCommerce

AI Verified

0

Show prices only for logged in users

Added: 1 year ago

Last Updated: 1 year ago

This code ensures that the prices in your store are only displayed for registered and logged in users. Visitors can not see prices.

WooCommerce

AI Verified

0

Show percent savings on sale

Added: 1 year ago

Last Updated: 1 year ago

You work a lot with offer prices? Then show your visitors how much they have saved compared to the original price.

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

2

Confirm Password Field in Woocommerce

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

2

Bypass logout confirmation.

Added: 1 year ago

Last Updated: 1 month ago

WooCommerce

AI Verified

2

Add Product Picture to Orderlist

Added: 1 year ago

Last Updated: 1 year ago