Created
July 17, 2019 12:51
-
-
Save bernattorras/d88f947d13b417d04e4713cbbcc77c72 to your computer and use it in GitHub Desktop.
Clears the cart when a specific page is loaded (it can also add a product to the cart automatically)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'template_redirect', 'clear_cart_when_loading_page' ); | |
function clear_cart_when_loading_page() { | |
$page_id = 124; | |
if ( is_page( $page_id ) ) { | |
WC()->cart->empty_cart(); | |
// Uncomment the next lines if you want to add a product to the cart automatically | |
// $product_id = 1098; | |
// WC()->cart->add_to_cart( $product_id ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment