Skip to content

Instantly share code, notes, and snippets.

@Niloys7
Created February 10, 2022 21:16
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Niloys7/e14c7b3690801e2ebead4dfb11f0b569 to your computer and use it in GitHub Desktop.
Hide Remove Button [x] from Specific product from WooCommerce Cart
add_filter( 'woocommerce_cart_item_remove_link', 'ns_cart_item_remove_link', 20, 2 );
/**
* @snippet Hide Remove Button [x] from Specific product from WooCommerce Cart
* @author Niloy , iamniloy.com
* @param $button_link
* @param $cart_item_key
* @return mixed
*/
function ns_cart_item_remove_link( $button_link, $cart_item_key ) {
//SET HERE your specific products IDs
$ns_products_ids = array( 74532 );
// Get the current cart item
$cart_item = WC()->cart->get_cart()[$cart_item_key];
// If product IDs in the cart remove the [x] button
if ( in_array( $cart_item['data']->get_id(), $ns_products_ids ) ) {
$button_link = '';
}
return $button_link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment