Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warnakey/62b80036500f6e362858d89907513495 to your computer and use it in GitHub Desktop.
Save warnakey/62b80036500f6e362858d89907513495 to your computer and use it in GitHub Desktop.
Clear things from the WooCommerce cart the first time you visit a page
// This would go in your functions.php file
// Clear things out of the cart the first time you visit a specific page (only run this script once)
add_action( 'template_redirect', 'clear_cart_items_custom_checkout' );
function clear_cart_items_custom_page() {
global $post;
$slug = $post->post_name;
if($slug == 'exclusive-invitation') { // Replace this with the Slug of the page you want to clear the cart on
global $woocommerce;
$woocommerce->cart->empty_cart();
}
}
// Make sure the script to empty things from the custom checkout page cart is only run once
add_action( 'init', 'my_run_only_once' );
function my_run_only_once() {
if (did_action('init') >= 2 )
return;
if(! get_option('run_create_vip_order_once')) {
clear_cart_items_custom_page(); // Run the function
update_option('run_create_vip_order_once', true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment