WC_Cart::restore_cart_item()
Restore a cart item.
Method of the class: WC_Cart{}
Hooks from the method
Return
true|false
.
Usage
$WC_Cart = new WC_Cart(); $WC_Cart->restore_cart_item( $cart_item_key );
- $cart_item_key(string) (required)
- Cart item key to restore to the cart.
WC_Cart::restore_cart_item() WC Cart::restore cart item code WC 9.6.0
public function restore_cart_item( $cart_item_key ) { if ( isset( $this->removed_cart_contents[ $cart_item_key ] ) ) { $restore_item = $this->removed_cart_contents[ $cart_item_key ]; $this->cart_contents[ $cart_item_key ] = $restore_item; $this->cart_contents[ $cart_item_key ]['data'] = wc_get_product( $restore_item['variation_id'] ? $restore_item['variation_id'] : $restore_item['product_id'] ); do_action( 'woocommerce_restore_cart_item', $cart_item_key, $this ); unset( $this->removed_cart_contents[ $cart_item_key ] ); do_action( 'woocommerce_cart_item_restored', $cart_item_key, $this ); return true; } return false; }