Skip to content

Instantly share code, notes, and snippets.

View friendorfoley's full-sized avatar

friendorfoley

  • Essex, UK
View GitHub Profile
@daigo75
daigo75 / woocommerce-restrict-cart-product-combinations.php
Last active July 10, 2023 21:12
WooCommerce – Only allow certain product combinations in cart
// Step 1 - Keep track of cart contents
add_action('wp_loaded', function() {
// This variable must be global, we will need it later. If this code were
// packaged as a plugin, a property could be used instead
global $allowed_cart_items;
// We decided that products with ID 737 and 832 can go together. If any of them
// is in the cart, all other products cannot be added to it
$restricted_cart_items = array(
737,
832,