Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Last active July 20, 2021 16:38
Show Gist options
  • Save plugin-republic/1450dff7d42a1a8dc57b5dfffac52921 to your computer and use it in GitHub Desktop.
Save plugin-republic/1450dff7d42a1a8dc57b5dfffac52921 to your computer and use it in GitHub Desktop.
<?php
/**
* Return a blank instead of the product for products that contain child products
*/
function my_prefix_cart_item_price( $price, $cart_item, $cart_item_key ) {
$product_id = $cart_item['data']->get_id();
// Add the product IDs here that contain child products
if( in_array( $product_id, array( 5121, 2222 ) ) ) {
// You can enter different text below if you wish
return '-';
}
return $price;
}
add_filter( 'woocommerce_cart_item_price', 'my_prefix_cart_item_price', 10, 3 );
function my_prefix_cart_item_subtotal( $subtotal, $cart_item, $cart_item_key ) {
$product_id = $cart_item['data']->get_id();
// Add the product IDs here that contain child products
if( in_array( $product_id, array( 5121, 2222 ) ) ) {
// You can enter different text below if you wish
return '-';
}
$subtotal;
}
add_filter( 'woocommerce_cart_item_subtotal', 'my_prefix_cart_item_subtotal', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment