Last active
August 1, 2016 17:19
-
-
Save asharirfan/848d6d64a281d4828740214568d13282 to your computer and use it in GitHub Desktop.
This functions limits the number of items in WooCommerce cart to only one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists( 'allow_only_one_subscription' ) ) { | |
/** | |
* allow_only_one_subscription. | |
* | |
* This functions limits the number of items in | |
* WooCommerce cart to only one. | |
* | |
* @since 1.3.2 | |
*/ | |
function allow_only_one_subscription( $valid, $product_id, $quantity ) { | |
if( ! empty ( WC()->cart->get_cart() ) && $valid ){ | |
WC()->cart->empty_cart(); | |
wc_add_notice( 'Whoa hold up! You can buy only one subscription at a time.', 'error' ); | |
} | |
return $valid; | |
} | |
add_filter( 'woocommerce_add_to_cart_validation', 'allow_only_one_subscription', 10, 3 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment