Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save manospsyx/2f4dfd67e1e9044cf363 to your computer and use it in GitHub Desktop.
Save manospsyx/2f4dfd67e1e9044cf363 to your computer and use it in GitHub Desktop.
Use this snippet to hide Components in the cart, checkout, order and e-mail templates
<?php
/**
* Plugin Name: WooCommerce Composite Products - Hide Components in all Templates
* Plugin URI: https://woocommerce.com/products/composite-products/
* Description: Use this snippet to hide Components in the cart, checkout, order and e-mail templates.
* Version: 1.0
* Author: SomewhereWarm
* Author URI: https://somewherewarm.gr/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 3.8
* Tested up to: 5.3
*
* Copyright: © 2017-2020 SomewhereWarm SMPC ([email protected]).
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// To use this snippet, download this file into your plugins directory and activate it, or copy the code under this line into the functions.php file of your (child) theme.
add_filter( 'woocommerce_order_item_visible', 'wc_cp_order_item_visible', 10, 2 );
add_filter( 'woocommerce_widget_cart_item_visible', 'wc_cp_cart_item_visible', 10, 3 );
add_filter( 'woocommerce_cart_item_visible', 'wc_cp_cart_item_visible' , 10, 3 );
add_filter( 'woocommerce_checkout_cart_item_visible', 'wc_cp_cart_item_visible', 10, 3 );
/** Visibility of components in orders.
*
* @param boolean $visible
* @param array $order_item
* @return boolean
*/
function wc_cp_order_item_visible( $visible, $order_item ) {
if ( ! empty( $order_item[ 'composite_parent' ] ) ) {
$visible = false;
}
return $visible;
}
/**
* Visibility of components in cart.
*
* @param boolean $visible
* @param array $cart_item
* @param string $cart_item_key
* @return boolean
*/
function wc_cp_cart_item_visible( $visible, $cart_item, $cart_item_key ) {
if ( ! empty( $cart_item[ 'composite_parent' ] ) ) {
$visible = false;
}
return $visible;
}
@manospsyx
Copy link
Author

manospsyx commented Sep 9, 2019

@ChampagneCoffee setting up the composited Bundles to utilize the Item Grouping > None option should hide their title in cart/order templates. In some cases this might be a better approach than hiding the entire Bundle container line items.

@martin-josef
Copy link

Hey Manos, apologies I also wrote you an email instead of commenting here. Is it possible to revers this snippet in a way to hide the parent in the order?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment