SILENT KILLERPanel

Current Path: > home > codekrsu > > cuddlebuds.lk > wp-content > > plugins > woocommerce > includes


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: /home/codekrsu//cuddlebuds.lk/wp-content//plugins/woocommerce/includes

NameTypeSizeLast ModifiedActions
abstracts Directory - -
admin Directory - -
blocks Directory - -
cli Directory - -
customizer Directory - -
data-stores Directory - -
emails Directory - -
export Directory - -
gateways Directory - -
import Directory - -
integrations Directory - -
interfaces Directory - -
legacy Directory - -
libraries Directory - -
log-handlers Directory - -
payment-tokens Directory - -
product-usage Directory - -
queue Directory - -
react-admin Directory - -
rest-api Directory - -
shipping Directory - -
shortcodes Directory - -
theme-support Directory - -
tracks Directory - -
traits Directory - -
walkers Directory - -
wccom-site Directory - -
widgets Directory - -
class-wc-ajax.php File 122567 bytes June 23 2025 19:46:28.
class-wc-auth.php File 12995 bytes July 30 2024 19:31:16.
class-wc-autoloader.php File 3401 bytes September 23 2024 20:44:04.
class-wc-background-emailer.php File 4685 bytes August 20 2020 23:18:50.
class-wc-background-updater.php File 3535 bytes August 20 2020 23:18:50.
class-wc-brands-brand-settings-manager.php File 1826 bytes September 23 2024 20:44:04.
class-wc-brands-coupons.php File 7059 bytes January 21 2025 18:53:44.
class-wc-brands.php File 34095 bytes July 07 2025 13:23:42.
class-wc-breadcrumb.php File 9722 bytes October 21 2020 03:38:50.
class-wc-cache-helper.php File 11438 bytes August 27 2024 23:04:44.
class-wc-cart-fees.php File 3448 bytes September 26 2023 21:42:36.
class-wc-cart-session.php File 20140 bytes June 23 2025 19:46:28.
class-wc-cart-totals.php File 29166 bytes July 07 2025 13:23:42.
class-wc-cart.php File 72605 bytes June 30 2025 17:49:22.
class-wc-checkout.php File 51349 bytes May 12 2025 21:07:28.
class-wc-cli.php File 2935 bytes May 12 2025 21:07:28.
class-wc-comments.php File 23066 bytes June 23 2025 19:46:28.
class-wc-countries.php File 50342 bytes May 12 2025 21:07:28.
class-wc-coupon.php File 40825 bytes June 23 2025 19:46:28.
class-wc-customer-download-log.php File 3452 bytes August 20 2020 23:18:50.
class-wc-customer-download.php File 10587 bytes July 30 2024 19:31:16.
class-wc-customer.php File 33300 bytes June 23 2025 19:46:28.
class-wc-data-exception.php File 1321 bytes May 23 2018 19:30:10.
class-wc-data-store.php File 6752 bytes October 19 2022 00:34:38.
class-wc-datetime.php File 2310 bytes April 20 2022 06:50:54.
class-wc-deprecated-action-hooks.php File 6746 bytes February 27 2024 18:59:46.
class-wc-deprecated-filter-hooks.php File 7518 bytes February 22 2023 07:17:34.
class-wc-discounts.php File 37476 bytes June 23 2025 19:46:28.
class-wc-download-handler.php File 29053 bytes December 18 2024 22:19:16.
class-wc-emails.php File 34457 bytes June 23 2025 19:46:28.
class-wc-embed.php File 4342 bytes January 21 2025 18:53:44.
class-wc-form-handler.php File 46932 bytes June 23 2025 19:46:28.
class-wc-frontend-scripts.php File 28511 bytes May 12 2025 21:07:28.
class-wc-geo-ip.php File 31139 bytes June 23 2025 19:46:28.
class-wc-geolite-integration.php File 2036 bytes January 16 2020 06:10:02.
class-wc-geolocation.php File 11594 bytes May 12 2025 21:07:28.
class-wc-https.php File 4439 bytes June 20 2023 23:45:50.
class-wc-install.php File 109669 bytes June 23 2025 19:46:28.
class-wc-integrations.php File 1308 bytes August 20 2020 23:18:50.
class-wc-log-levels.php File 3992 bytes January 30 2024 23:24:56.
class-wc-logger.php File 9601 bytes May 12 2025 21:07:28.
class-wc-meta-data.php File 2260 bytes April 20 2022 06:50:54.
class-wc-order-factory.php File 8728 bytes April 30 2024 19:35:34.
class-wc-order-item-coupon.php File 4175 bytes December 22 2021 00:24:58.
class-wc-order-item-fee.php File 9431 bytes March 03 2025 22:28:12.
class-wc-order-item-meta.php File 5942 bytes December 22 2021 00:24:58.
class-wc-order-item-product.php File 16221 bytes May 12 2025 21:07:28.
class-wc-order-item-shipping.php File 9013 bytes May 12 2025 21:07:28.
class-wc-order-item-tax.php File 6644 bytes December 22 2021 00:24:58.
class-wc-order-item.php File 18990 bytes May 12 2025 21:07:28.
class-wc-order-query.php File 2615 bytes July 28 2021 04:11:34.
class-wc-order-refund.php File 6135 bytes May 12 2025 21:07:28.
class-wc-order.php File 76529 bytes June 23 2025 19:46:28.
class-wc-payment-gateways.php File 16110 bytes June 30 2025 17:49:22.
class-wc-payment-tokens.php File 6390 bytes November 23 2022 05:58:58.
class-wc-post-data.php File 22246 bytes March 03 2025 22:28:12.
class-wc-post-types.php File 32771 bytes May 12 2025 21:07:28.
class-wc-privacy-background-process.php File 1833 bytes March 03 2025 22:28:12.
class-wc-privacy-erasers.php File 13935 bytes September 23 2024 20:44:04.
class-wc-privacy-exporters.php File 15044 bytes July 28 2021 04:11:34.
class-wc-privacy.php File 17629 bytes June 23 2025 19:46:28.
class-wc-product-attribute.php File 7137 bytes January 19 2022 02:24:34.
class-wc-product-download.php File 12547 bytes April 10 2024 16:54:10.
class-wc-product-external.php File 5104 bytes March 03 2025 22:28:12.
class-wc-product-factory.php File 3974 bytes January 21 2025 18:53:44.
class-wc-product-grouped.php File 5737 bytes May 12 2025 21:07:28.
class-wc-product-query.php File 2332 bytes January 21 2025 18:53:44.
class-wc-product-simple.php File 2762 bytes January 21 2025 18:53:44.
class-wc-product-variable.php File 25166 bytes June 02 2025 15:59:32.
class-wc-product-variation.php File 20661 bytes May 12 2025 21:07:28.
class-wc-query.php File 34161 bytes May 12 2025 21:07:28.
class-wc-rate-limiter.php File 4100 bytes December 01 2021 04:23:30.
class-wc-regenerate-images-request.php File 7923 bytes January 25 2023 03:19:12.
class-wc-regenerate-images.php File 15806 bytes June 25 2024 21:17:40.
class-wc-register-wp-admin-settings.php File 5171 bytes June 22 2021 15:24:06.
class-wc-rest-authentication.php File 22068 bytes June 25 2024 21:17:40.
class-wc-rest-exception.php File 276 bytes September 23 2020 01:16:50.
class-wc-session-handler.php File 21358 bytes July 14 2025 13:28:08.
class-wc-shipping-rate.php File 9566 bytes June 23 2025 19:46:28.
class-wc-shipping-zone.php File 13392 bytes September 23 2020 01:16:50.
class-wc-shipping-zones.php File 4106 bytes August 20 2020 23:18:50.
class-wc-shipping.php File 13160 bytes May 12 2025 21:07:28.
class-wc-shortcodes.php File 19274 bytes January 21 2025 18:53:44.
class-wc-structured-data.php File 24367 bytes March 03 2025 22:28:12.
class-wc-tax.php File 37969 bytes June 20 2023 23:45:50.
class-wc-template-loader.php File 21893 bytes June 09 2025 15:55:46.
class-wc-tracker.php File 50557 bytes June 23 2025 19:46:28.
class-wc-validation.php File 5929 bytes May 28 2024 14:28:20.
class-wc-webhook.php File 30111 bytes December 18 2024 22:19:16.
class-woocommerce.php File 51138 bytes July 23 2025 12:38:10.
wc-account-functions.php File 14449 bytes June 23 2025 19:46:28.
wc-attribute-functions.php File 21687 bytes January 21 2025 18:53:44.
wc-brands-functions.php File 4270 bytes September 23 2024 20:44:04.
wc-cart-functions.php File 21080 bytes June 30 2025 17:49:22.
wc-conditional-functions.php File 14916 bytes June 23 2025 19:46:28.
wc-core-functions.php File 88756 bytes June 30 2025 17:49:22.
wc-coupon-functions.php File 3169 bytes May 12 2025 21:07:28.
wc-deprecated-functions.php File 39030 bytes May 12 2025 21:07:28.
wc-formatting-functions.php File 50031 bytes June 30 2025 17:49:22.
wc-notice-functions.php File 8277 bytes June 23 2025 19:46:28.
wc-order-functions.php File 41609 bytes June 23 2025 19:46:28.
wc-order-item-functions.php File 5153 bytes January 25 2023 03:19:12.
wc-order-step-logger-functions.php File 5135 bytes May 12 2025 21:07:28.
wc-page-functions.php File 9657 bytes September 23 2024 20:44:04.
wc-product-functions.php File 59920 bytes June 23 2025 19:46:28.
wc-rest-functions.php File 14176 bytes June 23 2025 19:46:28.
wc-stock-functions.php File 17544 bytes January 21 2025 18:53:44.
wc-template-functions.php File 135937 bytes June 23 2025 19:46:28.
wc-template-hooks.php File 12957 bytes May 12 2025 21:07:28.
wc-term-functions.php File 24381 bytes June 16 2025 19:21:28.
wc-update-functions.php File 95221 bytes June 23 2025 19:46:28.
wc-user-functions.php File 35023 bytes June 23 2025 19:46:28.
wc-webhook-functions.php File 5905 bytes June 25 2024 21:17:40.
wc-widget-functions.php File 2063 bytes August 20 2020 23:18:50.

Reading File: /home/codekrsu//cuddlebuds.lk/wp-content//plugins/woocommerce/includes/class-wc-cart-session.php

<?php
/**
 * Cart session handling class.
 *
 * @package WooCommerce\Classes
 * @version 3.2.0
 */

use Automattic\WooCommerce\Enums\OrderStatus;
use Automattic\WooCommerce\Enums\ProductType;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * WC_Cart_Session class.
 *
 * @since 3.2.0
 */
final class WC_Cart_Session {

	/**
	 * Reference to cart object.
	 *
	 * @since 3.2.0
	 * @var WC_Cart
	 */
	protected $cart;

	/**
	 * Sets up the items provided, and calculate totals.
	 *
	 * @since 3.2.0
	 * @throws Exception If missing WC_Cart object.
	 *
	 * @param WC_Cart $cart Cart object to calculate totals for.
	 */
	public function __construct( $cart ) {
		if ( ! is_a( $cart, 'WC_Cart' ) ) {
			throw new Exception( 'A valid WC_Cart object is required' );
		}

		$this->set_cart( $cart );
	}

	/**
	 * Sets the cart instance.
	 *
	 * @param WC_Cart $cart Cart object.
	 */
	public function set_cart( WC_Cart $cart ) {
		$this->cart = $cart;
	}


	/**
	 * Register methods for this object on the appropriate WordPress hooks.
	 */
	public function init() {
		/**
		 * Filters whether hooks should be initialized for the current cart session.
		 *
		 * @param bool $must_initialize Will be passed as true, meaning that the cart hooks should be initialized.
		 * @param bool $session The WC_Cart_Session object that is being initialized.
		 * @returns bool True if the cart hooks should be actually initialized, false if not.
		 *
		 * @since 6.9.0
		 */
		if ( ! apply_filters( 'woocommerce_cart_session_initialize', true, $this ) ) {
			return;
		}

		add_action( 'wp_loaded', array( $this, 'get_cart_from_session' ) );
		add_action( 'woocommerce_cart_emptied', array( $this, 'destroy_cart_session' ) );
		add_action( 'woocommerce_after_calculate_totals', array( $this, 'set_session' ), 1000 );
		add_action( 'woocommerce_cart_loaded_from_session', array( $this, 'set_session' ) );
		add_action( 'woocommerce_removed_coupon', array( $this, 'set_session' ) );

		// Persistent cart stored to usermeta.
		add_action( 'woocommerce_add_to_cart', array( $this, 'persistent_cart_update' ) );
		add_action( 'woocommerce_cart_item_removed', array( $this, 'persistent_cart_update' ) );
		add_action( 'woocommerce_cart_item_restored', array( $this, 'persistent_cart_update' ) );
		add_action( 'woocommerce_cart_item_set_quantity', array( $this, 'persistent_cart_update' ) );

		// Cookie events - cart cookies need to be set before headers are sent.
		add_action( 'woocommerce_add_to_cart', array( $this, 'maybe_set_cart_cookies' ) );
		add_action( 'wp', array( $this, 'maybe_set_cart_cookies' ), 99 );
		add_action( 'shutdown', array( $this, 'maybe_set_cart_cookies' ), 0 );
	}

	/**
	 * Get the cart data from the PHP session and store it in class variables.
	 *
	 * @since 3.2.0
	 */
	public function get_cart_from_session() {
		do_action( 'woocommerce_load_cart_from_session' );
		$this->cart->set_totals( WC()->session->get( 'cart_totals', null ) );
		$this->cart->set_applied_coupons( WC()->session->get( 'applied_coupons', array() ) );
		$this->cart->set_coupon_discount_totals( WC()->session->get( 'coupon_discount_totals', array() ) );
		$this->cart->set_coupon_discount_tax_totals( WC()->session->get( 'coupon_discount_tax_totals', array() ) );
		$this->cart->set_removed_cart_contents( WC()->session->get( 'removed_cart_contents', array() ) );

		$update_cart_session = false; // Flag to indicate the stored cart should be updated.
		$order_again         = false; // Flag to indicate whether this is a re-order.
		$cart                = WC()->session->get( 'cart', null );
		$merge_saved_cart    = (bool) get_user_meta( get_current_user_id(), '_woocommerce_load_saved_cart_after_login', true );

		// Merge saved cart with current cart.
		if ( is_null( $cart ) || $merge_saved_cart ) {
			$saved_cart          = $this->get_saved_cart();
			$cart                = is_null( $cart ) ? array() : $cart;
			$cart                = array_merge( $saved_cart, $cart );
			$update_cart_session = true;

			delete_user_meta( get_current_user_id(), '_woocommerce_load_saved_cart_after_login' );
		}

		// Populate cart from order.
		if ( isset( $_GET['order_again'], $_GET['_wpnonce'] ) && is_user_logged_in() && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'woocommerce-order_again' ) ) { // WPCS: input var ok, sanitization ok.
			$cart                = $this->populate_cart_from_order( absint( $_GET['order_again'] ), $cart ); // WPCS: input var ok.
			$order_again         = true;
			$update_cart_session = true;
		}

		// Prime caches to reduce future queries.
		if ( is_callable( '_prime_post_caches' ) ) {
			_prime_post_caches( wp_list_pluck( $cart, 'product_id' ) );
		}

		$cart_contents = array();

		foreach ( $cart as $key => $values ) {
			if ( ! is_customize_preview() && 'customize-preview' === $key ) {
				continue;
			}

			$product = wc_get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );

			if ( empty( $product ) || ! $product->exists() || 0 >= $values['quantity'] ) {
				continue;
			}

			/**
			 * Allow 3rd parties to validate this item before it's added to cart and add their own notices.
			 *
			 * @since 3.6.0
			 *
			 * @param bool       $remove_cart_item_from_session If true, the item will not be added to the cart. Default: false.
			 * @param string     $key Cart item key.
			 * @param array      $values Cart item values e.g. quantity and product_id.
			 * @param WC_Product $product The product being added to the cart.
			 */
			if ( apply_filters( 'woocommerce_pre_remove_cart_item_from_session', false, $key, $values, $product ) ) {
				$update_cart_session = true;
				/**
				 * Fires when cart item is removed from the session.
				 *
				 * @since 3.6.0
				 *
				 * @param string     $key Cart item key.
				 * @param array      $values Cart item values e.g. quantity and product_id.
				 * @param WC_Product $product The product being added to the cart.
				 */
				do_action( 'woocommerce_remove_cart_item_from_session', $key, $values, $product );

				/**
				 * Allow 3rd parties to override this item's is_purchasable() result with cart item data.
				 *
				 * @param bool       $is_purchasable If false, the item will not be added to the cart. Default: product's is_purchasable() status.
				 * @param string     $key Cart item key.
				 * @param array      $values Cart item values e.g. quantity and product_id.
				 * @param WC_Product $product The product being added to the cart.
				 *
				 * @since 7.0.0
				 */
			} elseif ( ! apply_filters( 'woocommerce_cart_item_is_purchasable', $product->is_purchasable(), $key, $values, $product ) ) {
				$update_cart_session = true;
				/* translators: %s: product name */
				$message = sprintf( __( '%s has been removed from your cart because it can no longer be purchased. Please contact us if you need assistance.', 'woocommerce' ), $product->get_name() );
				/**
				 * Filter message about item removed from the cart.
				 *
				 * @since 3.8.0
				 * @param string     $message Message.
				 * @param WC_Product $product Product data.
				 */
				$message = apply_filters( 'woocommerce_cart_item_removed_message', $message, $product );
				wc_add_notice( $message, 'error' );
				do_action( 'woocommerce_remove_cart_item_from_session', $key, $values );

			} elseif ( ! empty( $values['data_hash'] ) && ! hash_equals( $values['data_hash'], wc_get_cart_item_data_hash( $product ) ) ) { // phpcs:ignore PHPCompatibility.PHP.NewFunctions.hash_equalsFound
				$update_cart_session = true;
				/* translators: %1$s: product name. %2$s product permalink */
				$message = sprintf( __( '%1$s has been removed from your cart because it has since been modified. You can add it back to your cart <a href="%2$s">here</a>.', 'woocommerce' ), $product->get_name(), $product->get_permalink() );
				$message = apply_filters( 'woocommerce_cart_item_removed_because_modified_message', $message, $product );
				wc_add_notice( $message, 'notice' );
				do_action( 'woocommerce_remove_cart_item_from_session', $key, $values );

			} else {
				// Put session data into array. Run through filter so other plugins can load their own session data.
				$session_data = array_merge(
					$values,
					array(
						'data' => $product,
					)
				);

				/**
				 * Filter to modify or add session data to the cart contents.
				 *
				 * @since 3.2.0
				 *
				 * @param array  $session_data Data for an item in the cart.
				 * @param array  $values       Data for an item in the cart, without the product object.
				 * @param string $key          The cart item hash.
				 */
				$cart_contents[ $key ] = apply_filters( 'woocommerce_get_cart_item_from_session', $session_data, $values, $key );
				if ( ! isset( $cart_contents[ $key ]['data'] ) || ! $cart_contents[ $key ]['data'] instanceof WC_Product ) {
					// If the cart contents is missing the product object after filtering, something is wrong.
					wc_doing_it_wrong(
						__METHOD__,
						'When filtering cart items with woocommerce_get_cart_item_from_session, each item must have a data key containing a product object.',
						'9.8.0'
					);

					// Add the product back in.
					$cart_contents[ $key ]['data'] = $product;
				}

				// Add to cart right away so the product is visible in woocommerce_get_cart_item_from_session hook.
				$this->cart->set_cart_contents( $cart_contents );
			}
		}

		// If it's not empty, it's been already populated by the loop above.
		if ( ! empty( $cart_contents ) ) {
			$this->cart->set_cart_contents( apply_filters( 'woocommerce_cart_contents_changed', $cart_contents ) );
		}

		do_action( 'woocommerce_cart_loaded_from_session', $this->cart );

		if ( $update_cart_session || is_null( WC()->session->get( 'cart_totals', null ) ) ) {
			$cart_for_session = $this->get_cart_for_session();
			WC()->session->set( 'cart', empty( $cart_for_session ) ? null : $cart_for_session );
			$this->cart->calculate_totals();

			if ( $merge_saved_cart ) {
				$this->persistent_cart_update();
			}
		}

		// If this is a re-order, redirect to the cart page to get rid of the `order_again` query string.
		if ( $order_again ) {
			wp_safe_redirect( wc_get_cart_url() );
			exit;
		}
	}

	/**
	 * Destroy cart session data.
	 *
	 * @since 3.2.0
	 */
	public function destroy_cart_session() {
		WC()->session->set( 'cart', null );
		WC()->session->set( 'cart_totals', null );
		WC()->session->set( 'applied_coupons', null );
		WC()->session->set( 'coupon_discount_totals', null );
		WC()->session->set( 'coupon_discount_tax_totals', null );
		WC()->session->set( 'removed_cart_contents', null );
		WC()->session->set( 'order_awaiting_payment', null );
	}

	/**
	 * Will set cart cookies if needed and when possible.
	 *
	 * Headers are only updated if headers have not yet been sent.
	 *
	 * @since 3.2.0
	 */
	public function maybe_set_cart_cookies() {
		if ( headers_sent() || ! did_action( 'wp_loaded' ) ) {
			return;
		}
		if ( ! $this->cart->is_empty() ) {
			$this->set_cart_cookies( true );
		} elseif ( isset( $_COOKIE['woocommerce_items_in_cart'] ) ) { // WPCS: input var ok.
			$this->set_cart_cookies( false );
		}
		$this->dedupe_cookies();
	}

	/**
	 * Remove duplicate cookies from the response.
	 */
	private function dedupe_cookies() {
		$all_cookies    = array_filter(
			headers_list(),
			function( $header ) {
				return stripos( $header, 'Set-Cookie:' ) !== false;
			}
		);
		$final_cookies  = array();
		$update_cookies = false;
		foreach ( $all_cookies as $cookie ) {

			list(, $cookie_value)             = explode( ':', $cookie, 2 );
			list($cookie_name, $cookie_value) = explode( '=', trim( $cookie_value ), 2 );

			if ( stripos( $cookie_name, 'woocommerce_' ) !== false ) {
				$key = $this->find_cookie_by_name( $cookie_name, $final_cookies );
				if ( false !== $key ) {
					$update_cookies = true;
					unset( $final_cookies[ $key ] );
				}
			}
			$final_cookies[] = $cookie;
		}

		if ( $update_cookies ) {
			header_remove( 'Set-Cookie' );
			foreach ( $final_cookies as $cookie ) {
				// Using header here preserves previous cookie args.
				header( $cookie, false );
			}
		}
	}

	/**
	 * Find a cookie by name in an array of cookies.
	 *
	 * @param  string $cookie_name Name of the cookie to find.
	 * @param  array  $cookies     Array of cookies to search.
	 * @return mixed               Key of the cookie if found, false if not.
	 */
	private function find_cookie_by_name( $cookie_name, $cookies ) {
		foreach ( $cookies as $key => $cookie ) {
			if ( strpos( $cookie, $cookie_name ) !== false ) {
				return $key;
			}
		}
		return false;
	}

	/**
	 * Sets the php session data for the cart and coupons.
	 */
	public function set_session() {
		$wc_session = WC()->session;

		$cart                       = $this->get_cart_for_session();
		$applied_coupons            = $this->cart->get_applied_coupons();
		$coupon_discount_totals     = $this->cart->get_coupon_discount_totals();
		$coupon_discount_tax_totals = $this->cart->get_coupon_discount_tax_totals();
		$removed_cart_contents      = $this->cart->get_removed_cart_contents();

		/*
		 * We want to clear out any empty/default data from the session that have no value in being stored so the session
		 * can be forgotten if empty.
		 */
		$wc_session->set( 'cart_totals', empty( $cart ) ? null : $this->cart->get_totals() );
		$wc_session->set( 'cart', empty( $cart ) ? null : $cart );
		$wc_session->set( 'applied_coupons', empty( $applied_coupons ) ? null : $applied_coupons );
		$wc_session->set( 'coupon_discount_totals', empty( $coupon_discount_totals ) ? null : $coupon_discount_totals );
		$wc_session->set( 'coupon_discount_tax_totals', empty( $coupon_discount_tax_totals ) ? null : $coupon_discount_tax_totals );
		$wc_session->set( 'removed_cart_contents', empty( $removed_cart_contents ) ? null : $removed_cart_contents );

		do_action( 'woocommerce_cart_updated' );
	}

	/**
	 * Returns the contents of the cart in an array without the 'data' element.
	 *
	 * @return array contents of the cart
	 */
	public function get_cart_for_session() {
		$cart_session = array();

		foreach ( $this->cart->get_cart() as $key => $values ) {
			$cart_session[ $key ] = $values;
			unset( $cart_session[ $key ]['data'] ); // Unset product object.
		}

		return $cart_session;
	}

	/**
	 * Save the persistent cart when the cart is updated.
	 */
	public function persistent_cart_update() {
		if ( get_current_user_id() && apply_filters( 'woocommerce_persistent_cart_enabled', true ) ) {
			update_user_meta(
				get_current_user_id(),
				'_woocommerce_persistent_cart_' . get_current_blog_id(),
				array(
					'cart' => $this->get_cart_for_session(),
				)
			);
		}
	}

	/**
	 * Delete the persistent cart permanently.
	 */
	public function persistent_cart_destroy() {
		if ( get_current_user_id() && apply_filters( 'woocommerce_persistent_cart_enabled', true ) ) {
			delete_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id() );
		}
	}

	/**
	 * Set cart hash cookie and items in cart if not already set.
	 *
	 * @param bool $set Should cookies be set (true) or unset.
	 */
	private function set_cart_cookies( $set = true ) {
		if ( $set ) {
			$setcookies = array(
				'woocommerce_items_in_cart' => '1',
				'woocommerce_cart_hash'     => WC()->cart->get_cart_hash(),
			);
			foreach ( $setcookies as $name => $value ) {
				if ( ! isset( $_COOKIE[ $name ] ) || $_COOKIE[ $name ] !== $value ) {
					wc_setcookie( $name, $value );
					$_COOKIE[ $name ] = $value;
				}
			}
		} else {
			$unsetcookies = array(
				'woocommerce_items_in_cart',
				'woocommerce_cart_hash',
			);
			foreach ( $unsetcookies as $name ) {
				if ( isset( $_COOKIE[ $name ] ) ) {
					wc_setcookie( $name, 0, time() - HOUR_IN_SECONDS );
					unset( $_COOKIE[ $name ] );
				}
			}
		}

		do_action( 'woocommerce_set_cart_cookies', $set );
	}

	/**
	 * Get the persistent cart from the database.
	 *
	 * @since  3.5.0
	 * @return array
	 */
	private function get_saved_cart() {
		$saved_cart = array();

		if ( apply_filters( 'woocommerce_persistent_cart_enabled', true ) ) {
			$saved_cart_meta = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true );

			if ( is_array( $saved_cart_meta ) && isset( $saved_cart_meta['cart'] ) ) {
				$saved_cart = array_filter( (array) $saved_cart_meta['cart'] );
			}
		}

		return $saved_cart;
	}

	/**
	 * Get a cart from an order, if user has permission.
	 *
	 * @since  3.5.0
	 *
	 * @param int   $order_id Order ID to try to load.
	 * @param array $cart Current cart array.
	 *
	 * @return array
	 */
	private function populate_cart_from_order( $order_id, $cart ) {
		$order = wc_get_order( $order_id );

		/**
		 * Filter the valid order statuses for reordering.
		 *
		 * @since 3.6.0
		 *
		 * @param array $valid_statuses Array of valid order statuses.
		 */
		$valid_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_order_again', array( OrderStatus::COMPLETED ) );
		if ( ! $order->get_id() || ! $order->has_status( $valid_statuses ) || ! current_user_can( 'order_again', $order->get_id() ) ) {
			return;
		}

		if ( apply_filters( 'woocommerce_empty_cart_when_order_again', true ) ) {
			$cart = array();
		}

		$inital_cart_size = count( $cart );
		$order_items      = $order->get_items();

		foreach ( $order_items as $item ) {
			$product_id     = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $item->get_product_id() );
			$quantity       = $item->get_quantity();
			$variation_id   = (int) $item->get_variation_id();
			$variations     = array();
			$cart_item_data = apply_filters( 'woocommerce_order_again_cart_item_data', array(), $item, $order );
			$product        = $item->get_product();

			if ( ! $product ) {
				continue;
			}

			// Prevent reordering variable products if no selected variation.
			if ( ! $variation_id && $product->is_type( ProductType::VARIABLE ) ) {
				continue;
			}

			// Prevent reordering items specifically out of stock.
			if ( ! $product->is_in_stock() ) {
				continue;
			}

			foreach ( $item->get_meta_data() as $meta ) {
				if ( taxonomy_is_product_attribute( $meta->key ) || meta_is_product_attribute( $meta->key, $meta->value, $product_id ) ) {
					$variations[ $meta->key ] = $meta->value;
				}
			}

			if ( ! apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations, $cart_item_data ) ) {
				continue;
			}

			// Add to cart directly.
			$cart_id          = WC()->cart->generate_cart_id( $product_id, $variation_id, $variations, $cart_item_data );
			$product_data     = wc_get_product( $variation_id ? $variation_id : $product_id );
			$cart[ $cart_id ] = apply_filters(
				'woocommerce_add_order_again_cart_item',
				array_merge(
					$cart_item_data,
					array(
						'key'          => $cart_id,
						'product_id'   => $product_id,
						'variation_id' => $variation_id,
						'variation'    => $variations,
						'quantity'     => $quantity,
						'data'         => $product_data,
						'data_hash'    => wc_get_cart_item_data_hash( $product_data ),
					)
				),
				$cart_id
			);
		}

		do_action_ref_array( 'woocommerce_ordered_again', array( $order->get_id(), $order_items, &$cart ) );

		$num_items_in_cart           = count( $cart );
		$num_items_in_original_order = count( $order_items );
		$num_items_added             = $num_items_in_cart - $inital_cart_size;

		if ( $num_items_in_original_order > $num_items_added ) {
			wc_add_notice(
				sprintf(
					/* translators: %d item count */
					_n(
						'%d item from your previous order is currently unavailable and could not be added to your cart.',
						'%d items from your previous order are currently unavailable and could not be added to your cart.',
						$num_items_in_original_order - $num_items_added,
						'woocommerce'
					),
					$num_items_in_original_order - $num_items_added
				),
				'error'
			);
		}

		if ( 0 < $num_items_added ) {
			wc_add_notice( __( 'The cart has been filled with the items from your previous order.', 'woocommerce' ) );
		}

		return $cart;
	}
}

SILENT KILLER Tool