Last active
October 9, 2023 13:55
-
-
Save bryceadams/db6c8669e9e99cb2808c to your computer and use it in GitHub Desktop.
Clear WooCommerce Cart (when not cart/checkout)
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
/** | |
* Clears WC Cart on Page Load | |
* (Only when not on cart/checkout page) | |
*/ | |
add_action( 'wp_head', 'bryce_clear_cart' ); | |
function bryce_clear_cart() { | |
if ( wc_get_page_id( 'cart' ) == get_the_ID() || wc_get_page_id( 'checkout' ) == get_the_ID() ) { | |
return; | |
} | |
WC()->cart->empty_cart( true ); | |
} |
Author
bryceadams
commented
Oct 8, 2020
via email
I wrote the code like 5 years ago so honestly don't remember at all. Best
of luck with it!
…On Thu, Oct 8, 2020, 15:55 Srinivas ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
can u pls explain this logic :
if ( wc_get_page_id( 'cart' ) == get_the_ID() || wc_get_page_id(
'checkout' ) == get_the_ID() ) {
return;
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/db6c8669e9e99cb2808c#gistcomment-3481530>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALWEQRIROPAPN4A37MZ4OTSJVA25ANCNFSM4SIHJLFQ>
.
Sorry, I'm just beginner. Where do I have to insert that code? I am using child theme, so I copied the woocommerce.php file to child theme and inserted that code into that file, but it didn't fix the problem.
Thank you so much!!!
You've been very helpful! I've been looking for this for! Thank you so much!
Just tested and this still works! For anyone who might find this in the future:
Just copy and paste this code to the bottom of your functions.php file. To find this file, go to your web host File Manager then navigate to wp-content > themes > [ choose your current active theme ] > functions.php.
Thanks @bryceadams It still works!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment