mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/76667057/how-to-clear-woocommerce-cart-when-user-visit-any-product-page
12 lines
426 B
Text
12 lines
426 B
Text
function clear_cart_on_membership_level_change() {
|
|
|
|
// Check if the current page is a product
|
|
if ( is_product() ) {
|
|
|
|
// If the membership level is available, empty the cart
|
|
if ( pmpro_hasMembershipLevel( array( 'bronze', 'silver', 'gold' ) ) ) {
|
|
WC()->cart->empty_cart();
|
|
}
|
|
}
|
|
}
|
|
add_action( 'woocommerce_before_single_product', 'clear_cart_on_membership_level_change' );
|