Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save vishalbasnet23/afba5b4fb9e6f0d564f7 to your computer and use it in GitHub Desktop.

Select an option

Save vishalbasnet23/afba5b4fb9e6f0d564f7 to your computer and use it in GitHub Desktop.
Woocommerce remove item if that item is already is in cart.
<?php
global $woocommerce;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
if($cart_item['product_id'] == $current_package_id ){
$remove_url = $woocommerce->cart->get_remove_url( $cart_item_key );
echo '<a href="'.$remove_url.'class="remove-item">Remove</a>
<script>
jQuery('a.remove-item').trigger('click');
window.location.href = "'.home_url().'/foo/";
</script>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment