Home » WooCommerce: Hide Hidden Products From Cart, Order, Emails

WooCommerce: Hide Hidden Products From Cart, Order, Emails

by adminkys

While working on a workaround for a client, I had to hide a hidden product from the cart, checkout, order received and emails. Hidden products already don’t show on the shop and category pages, but they do show on the cart if they’re added to cart “programmatically”.

A tough task, but as usual here I come with the solution 🙂

First, make your WooCommerce product hidden!
The wanted result: hide Hidden Products from the Cart (and also Checkout, Order Received and Emails!)

PHP Snippet: Hide Hidden Products from WooCommerce Cart, Checkout, Order, Emails

/**
 * @snippet       Hide Hidden Products from Cart, Checkout, Order - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 4.1
 * @donate $9     https://www.tutoraspire.com
 */
  
add_filter( 'woocommerce_cart_item_visible', 'tutoraspire_hide_hidden_product_from_cart' , 10, 3 );
add_filter( 'woocommerce_widget_cart_item_visible', 'tutoraspire_hide_hidden_product_from_cart', 10, 3 );
add_filter( 'woocommerce_checkout_cart_item_visible', 'tutoraspire_hide_hidden_product_from_cart', 10, 3 );
add_filter( 'woocommerce_order_item_visible', 'tutoraspire_hide_hidden_product_from_order_woo333', 10, 2 );
   
function tutoraspire_hide_hidden_product_from_cart( $visible, $cart_item, $cart_item_key ) {
    $product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
    if ( $product->get_catalog_visibility() == 'hidden' ) {
        $visible = false;
    }
    return $visible;
}
   
function tutoraspire_hide_hidden_product_from_order_woo333( $visible, $order_item ) {
    $product = $order_item->get_product();
    if ( $product->get_catalog_visibility() == 'hidden' ) {
        $visible = false;
    }
    return $visible;
}

You may also like