WC_Cart::check_cart_item_validity
Looks through cart items and checks the posts are not trashed or deleted.
Method of the class: WC_Cart{}
No Hooks.
Returns
true|false|WP_Error.
Usage
$WC_Cart = new WC_Cart(); $WC_Cart->check_cart_item_validity();
WC_Cart::check_cart_item_validity() WC Cart::check cart item validity code WC 10.7.0
public function check_cart_item_validity() {
$return = true;
foreach ( $this->get_cart() as $cart_item_key => $values ) {
$product = $values['data'];
if ( ! $product || ! $product->exists() || ProductStatus::TRASH === $product->get_status() ) {
$this->set_quantity( $cart_item_key, 0 );
$return = new WP_Error( 'invalid', __( 'An item which is no longer available was removed from your cart.', 'woocommerce' ) );
}
}
return $return;
}