Last active
November 22, 2021 04:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
@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.
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
So I have a complex product. It is a composite product with a number of bundles products within it as well as variable, virtual products. I have been searching all day for a way to hide the variable virtual components and just have the main item "Gift Hamper" and the bundled item visible i.e. chocolate flavour rather than the box size and the 'choose 6 chocolates' component which have magically vanished. No idea how you know what to scrap, but you did it! Thank you :)