Skip to content

Instantly share code, notes, and snippets.

View Firestorm-Graphics's full-sized avatar

Firestorm Graphics Firestorm-Graphics

View GitHub Profile
@Firestorm-Graphics
Firestorm-Graphics / functions.php
Created August 21, 2017 07:56 — forked from yojance/functions.php
Removing a Product From The Cart Programatically In WooCommerce
<?php
add_action( 'template_redirect', 'remove_product_from_cart' );
function remove_product_from_cart() {
// Run only in the Cart or Checkout Page
if( is_cart() || is_checkout() ) {
// Set the product ID to remove
$prod_to_remove = 56;
// Cycle through each product in the cart
foreach( WC()->cart->cart_contents as $prod_in_cart ) {