WooCommerce: ottenere un riferimento ad un prodotto rimosso dal carrello

In WooCommerce possiamo ottenere un riferimento ad un prodotto rimosso dal carrello.

WordPress di Gabriele Romanato

In WooCommerce possiamo ottenere un riferimento ad un prodotto rimosso dal carrello.

La soluzione รจ la seguente:


<?php

function my_after_remove_product_from_cart( $removed_cart_item_key, $cart ) {
    $line_item = $cart->removed_cart_contents[ $removed_cart_item_key ];
    $product_id = $line_item[ 'product_id' ];
    $product_removed = wc_get_product( $product_id );
}

add_action( 'woocommerce_cart_item_removed', 'my_after_remove_product_from_cart', 10, 2 );

Commenti