Answer the question
In order to leave comments, you need to log in
Can I pass my data through Woocommerce snippets?
This is the code to remove an item from the cart
add_action('wp_ajax_remove_cart_item', 'remove_cart_item');
add_action('wp_ajax_nopriv_remove_cart_item', 'remove_cart_item');
function remove_cart_item() {
global $woocommerce;
$cart_id = wc_clean($_POST['cart_id']);
if(WC()->cart->remove_cart_item($cart_id)) {
WC_AJAX::get_refreshed_fragments();
} else {
$data = array(
'error' => true
);
echo wp_send_json($data);
}
wp_die();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question