Skip to content

Instantly share code, notes, and snippets.

@somewherewarm-snippets
Last active November 17, 2021 14:27
Show Gist options
  • Save somewherewarm-snippets/2611a5baab8b819e84d28dfd7073e9dc to your computer and use it in GitHub Desktop.
Save somewherewarm-snippets/2611a5baab8b819e84d28dfd7073e9dc to your computer and use it in GitHub Desktop.
<?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: WooCommerce
* Author URI: https://woocommerce.com/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 3.8
* Tested up to: 5.3
*
* Copyright: © 2021 Automattic.
* 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment