F A

Generation

generate functionWed, 22 Feb 2023

I want to remove woocommerce product from the user's cart after 12 hours

function remove_product_from_cart() { global $woocommerce; foreach($woocommerce->cart->get_cart() as $cart_item_key => $cart_values) { // get the product id $product_id = $cart_values['product_id']; // get the variation id if it exists $variation_id = ( isset( $cart_values['variation_id'] ) ) ? $cart_values['variation_id'] : ''; // get the product quantity $quantity = $cart_values['quantity']; // remove the product from the cart $woocommerce->cart->remove_cart_item($cart_item_key); } } add_action( 'woocommerce_before_cart_item_quantity_zero', 'remove_product_from_cart' );

Questions about programming?Chat with your personal AI assistant