Disable specific products from showing on the cart page in WooCommerce

Disable specific products from showing on the cart page in WooCommerce on child sites.

Snippet Type

Execute on Child Sites

Snippet

function filter_woocommerce_cart_item_visible( $true, $cart_item, $cart_item_key ) {    
    // The targeted product ids
    $targeted_ids = array( 30, 53 );

    // Computes the intersection of arrays
    if ( ! array_intersect( $targeted_ids, array( $cart_item['product_id'], $cart_item['variation_id'] ) ) ) {
        $true = false;
    }
    
    return $true; 
}
add_filter( 'woocommerce_cart_item_visible', 'filter_woocommerce_cart_item_visible', 10, 3 ); 
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.