In my woocommerce website, i have products that i want to make it only available in cartflows funnels but not in woocommerce. but now whenever i visit a cartflows funnel, the product automatically adds into the cart in woocommerce.
I know that cartflows is build around woocommerce but is there a way to separate both side? i have tried with the below php code but it hides both sides.
function remove_course_category_products_from_cart( $cart_item_key ) {
// Define the category slug to remove
$category_slug_to_remove = 'course-category'; // Replace with your category slug
// Check if we're on a CartFlows page by looking for a specific CartFlows body class
if ( function_exists('is_cartflows_page') && is_cartflows_page() ) {
return; // Do nothing on CartFlows pages
}
foreach ( WC()->cart->get_cart() as $key => $cart_item ) {
// Get the product ID
$product_id = $cart_item['product_id'];
// Check if the product belongs to the specified category
if ( has_term( $category_slug_to_remove, 'product_cat', $product_id ) ) {
// Remove the product from the cart
WC()->cart->remove_cart_item( $key );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'remove_course_category_products_from_cart', 10, 1 );
// Function to check if it's a CartFlows page
function is_cartflows_page() {
return ( function_exists( 'cartflows' ) && ( cartflows()->is_checkout_flow() || cartflows()->is_checkout_page() || cartflows()->is_thankyou_page() || cartflows()->is_optin_page() ) );
}
Khai Ren is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.