Skip to content

Instantly share code, notes, and snippets.

@ahmedMshaban
ahmedMshaban / function.php
Created January 20, 2023 07:56
Handle products and product in categories that can not be sold or shipped with anything else
/**
* Description: Handle products and product in categories that can not be sold or shipped with anything else
*/
add_filter( 'woocommerce_add_to_cart_validation', 'wc_add_to_cart_validation_filter_callback', 10, 3 );
function wc_add_to_cart_validation_filter_callback( $passed, $product_id, $quantity ) {
if( WC()->cart->is_empty() )
return $passed;
// List of product Ids that can not be sold with anything else