Skip to content

Instantly share code, notes, and snippets.

@rajeshsingh520
Last active June 17, 2024 00:31
Show Gist options
  • Save rajeshsingh520/60a7bb107c55f86dd31e40264b929200 to your computer and use it in GitHub Desktop.
Save rajeshsingh520/60a7bb107c55f86dd31e40264b929200 to your computer and use it in GitHub Desktop.
This allows you to disable pickup option when product from specific categories are in the cart, in below example we have used category 19, 36
add_filter('pisol_dtt_setting_filter_pi_type', function( $val ){
$disable_pickup_for_category = [19];
if ( ! did_action( 'wp_loaded' ) ) return 'Both';
if(function_exists('WC') && isset(WC()->cart) && is_object(WC()->cart)){
foreach( WC()->cart->get_cart() as $cart_item ) {
$product_in_cart = $cart_item['product_id'];
if(has_term($disable_pickup_for_category, 'product_cat', $product_in_cart)){
return 'Delivery';
}
}
}
return $val;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment