Skip to content

Instantly share code, notes, and snippets.

@elias1435
Created February 9, 2024 11:22
Show Gist options
  • Save elias1435/7940820be66a7bc2ea463c6ae387cc83 to your computer and use it in GitHub Desktop.
Save elias1435/7940820be66a7bc2ea463c6ae387cc83 to your computer and use it in GitHub Desktop.
WooCommerce: Only Allow 1 Product in the Cart. Place this code in functions.php
add_filter( 'woocommerce_add_to_cart_validation', 'product_only_one_in_cart', 9999 );
function product_only_one_in_cart( $passed ) {
wc_empty_cart();
return $passed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment