Hide Hidden Products From Cart, Order, Emails

I had to hide a hidden product from the cart, checkout, order received, and emails. Hidden products are already hidden on the store and category sites, but if they’re added to the cart “programmatically,” they’ll appear in the cart. Simply copy and paste the following snippet into your Functions.php file.

add_filter( 'woocommerce_cart_item_visible', 'codeithub_hide_hidden_product_from_cart' , 10, 3 );
add_filter( 'woocommerce_widget_cart_item_visible', 'codeithub_hide_hidden_product_from_cart', 10, 3 );
add_filter( 'woocommerce_checkout_cart_item_visible', 'codeithub_hide_hidden_product_from_cart', 10, 3 );
add_filter( 'woocommerce_order_item_visible', 'codeithub_hide_hidden_product_from_order_woo333', 10, 2 );
    
function codeithub_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 codeithub_hide_hidden_product_from_order_woo333( $visible, $order_item ) {
    $product = $order_item->get_product();
    if ( $product->get_catalog_visibility() == 'hidden' ) {
        $visible = false;
    }
    return $visible;
}
Hidden Catalog Visibility

Before:

See also  Redirect to checkout page after add to cart
Visible Hidden Product on Cart

After:

Hide Hidden Products From Cart

Leave a Reply

Your email address will not be published. Required fields are marked *