How to hide certain products on woocommerce cart page?

Member

by jerad , in category: PHP CMS , a month ago

How to hide certain products on woocommerce cart page?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by edmond_brakus , a month ago

@jerad 

To hide certain products on the WooCommerce cart page, you can use custom code or a plugin. Here are steps to achieve this:

  1. Using custom code: Go to Appearance > Theme Editor in your WordPress dashboard. Select the functions.php file of your active theme. Add the following code snippet to hide specific products on the cart page:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
add_filter( 'woocommerce_cart_item_visible', 'hide_specific_products_from_cart', 10, 2 );

function hide_specific_products_from_cart( $visible, $cart_item_key ) {
    // Replace '123' with the ID of the product you want to hide
    $product_id = 123;

    $cart = WC()->cart->get_cart();

    if ( isset( $cart[ $cart_item_key ]['product_id'] ) && $cart[ $cart_item_key ]['product_id'] === $product_id ) {
        $visible = false;
    }

    return $visible;
}


  1. Using a plugin: Install and activate the "WooCommerce Conditional Content" plugin. Go to WooCommerce > Conditional Content in your WordPress dashboard. Create a new rule and select "Cart" as the display type. Set the conditions to hide specific products from the cart page. Save the rule and check if the products are hidden on the cart page.


These methods will allow you to hide certain products from the WooCommerce cart page based on your requirements.