$22 GRAYBYTE WORDPRESS FILE MANAGER $43

SERVER : premium134.web-hosting.com #1 SMP Thu Mar 13 14:29:12 UTC 2025
SERVER IP : 162.0.232.104 | ADMIN IP 216.73.216.80
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/home/raydofqv/ctdatabase.work/wp-content/plugins/woocommerce/includes/

HOME
Current File : /home/raydofqv/ctdatabase.work/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_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 );

		add_action( 'template_redirect', array( $this, 'clean_up_removed_cart_contents' ) );
	}

	/**
	 * Get the cart data from the PHP session and store it in class variables.
	 *
	 * @since 3.2.0
	 */
	public function get_cart_from_session() {
		/**
		 * Fires when cart is loaded from session.
		 *
		 * @since 3.2.0
		 */
		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' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
			$cart                = $this->populate_cart_from_order( absint( $_GET['order_again'] ), $cart );
			$order_again         = true;
			$update_cart_session = true;
		}

		if ( ! empty( $cart ) ) {
			// Prime caches to reduce future queries.
			_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' );
				/**
				 * 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.
				 */
				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() );

				/**
				 * Filter message about item removed from the cart because it has since been modified.
				 *
				 * @since 3.8.0
				 * @param string     $message Message.
				 * @param WC_Product $product Product data.
				 */
				$message = apply_filters( 'woocommerce_cart_item_removed_because_modified_message', $message, $product );
				wc_add_notice( $message, 'notice' );

				/**
				 * 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.
				 */
				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 ) ) {
			/**
			 * Filter the cart contents.
			 *
			 * @since 3.2.0
			 *
			 * @param array $cart_contents The cart contents.
			 */
			$this->cart->set_cart_contents( apply_filters( 'woocommerce_cart_contents_changed', $cart_contents ) );
		}

		/**
		 * Fires when cart is loaded from session.
		 *
		 * @since 3.2.0
		 *
		 * @param WC_Cart $cart The cart object.
		 */
		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 || $update_cart_session ) {
				$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 = WC()->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 );
		$wc_session->set( 'store_api_draft_order', null );
		$wc_session->set( 'shipping_method_counts', null );
		$wc_session->set( 'previous_shipping_methods', null );
		$wc_session->set( 'chosen_shipping_methods', null );
		$this->remove_shipping_for_package_from_session();
	}

	/**
	 * 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 );
		if ( ! $this->cart_has_shippable_products() ) {
			$wc_session->set( 'shipping_method_counts', null );
			$wc_session->set( 'previous_shipping_methods', null );
			$wc_session->set( 'chosen_shipping_methods', null );
			$this->remove_shipping_for_package_from_session();
		}
		if ( empty( $cart ) ) {
			$wc_session->set( 'store_api_draft_order', null );
		}

		/**
		 * Fires when cart is updated.
		 *
		 * @since 3.2.0
		 */
		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() {
		/**
		 * Filters whether the persistent cart is enabled.
		 *
		 * @since 3.4.0
		 * @param bool $enabled Whether the persistent cart is enabled. Default true.
		 */
		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() {
		/**
		 * Filters whether the persistent cart is enabled.
		 *
		 * @since 3.4.0
		 * @param bool $enabled Whether the persistent cart is enabled. Default true.
		 */
		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();

		/**
		 * Filters whether the persistent cart is enabled.
		 *
		 * @since 3.4.0
		 * @param bool $enabled Whether the persistent cart is enabled. Default true.
		 */
		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 ) ) {
					$attribute_key = 'attribute_' . sanitize_title( $meta->key );
					if ( taxonomy_is_product_attribute( $meta->key ) ) {
						$variations[ $attribute_key ] = sanitize_title( $meta->value );
					} else {
						$variations[ $attribute_key ] = html_entity_decode( wc_clean( $meta->value ), ENT_QUOTES, get_bloginfo( 'charset' ) );
					}
				}
			}

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

			$product_data = wc_get_product( $variation_id ? $variation_id : $product_id );
			if ( $product_data instanceof WC_Product && $product_data->is_sold_individually() ) {
				// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- Filter documented in CartController::validate_add_to_cart().
				$quantity = apply_filters( 'woocommerce_add_to_cart_sold_individually_quantity', 1, $quantity, $product_id, $variation_id, $cart_item_data );

				$cart_id = WC()->cart->generate_cart_id( $product_id, $variation_id, $variations, $cart_item_data );
				// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- Filter first added in WC_Cart::add_to_cart(), add documentation there.
				$found_in_cart = apply_filters( 'woocommerce_add_to_cart_sold_individually_found_in_cart', isset( $cart[ $cart_id ] ) && isset( $cart[ $cart_id ]['quantity'] ) && $cart[ $cart_id ]['quantity'] > 0, $product_id, $variation_id, $cart_item_data, $cart_id );
				if ( $found_in_cart ) {
					/* translators: %s: product name */
					$message = sprintf( __( 'You cannot add another "%s" to your cart.', 'woocommerce' ), $product_data->get_name() );
					// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- Filter documented in WC_Cart::add_to_cart().
					$message         = apply_filters( 'woocommerce_cart_product_cannot_add_another_message', $message, $product_data );
					$wp_button_class = wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '';
					$message         = sprintf( '%s <a href="%s" class="button wc-forward%s">%s</a>', $message, esc_url( wc_get_cart_url() ), esc_attr( $wp_button_class ), __( 'View cart', 'woocommerce' ) );
					wc_add_notice( $message, 'error' );
					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;
	}

	/**
	 * Remove shipping data for all packages from session.
	 *
	 * @return void
	 */
	private function remove_shipping_for_package_from_session() {
		$wc_session = WC()->session;

		if ( ! is_a( $wc_session, 'WC_Session_Handler' ) ) {
			return;
		}

		foreach ( array_keys( $wc_session->get_session_data() ) as $key ) {
			if ( 0 === strpos( $key, 'shipping_for_package_' ) ) {
				$wc_session->set( $key, null );
			}
		}
	}

	/**
	 * Check if the cart has shippable products.
	 *
	 * @return bool
	 */
	private function cart_has_shippable_products() {
		foreach ( $this->cart->get_cart() as $cart_item ) {
			if ( $cart_item['data']->needs_shipping() ) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Removes items from the removed cart contents on next user initiated request.
	 *
	 * @return void
	 */
	public function clean_up_removed_cart_contents() {
		// Limit to page requests initiated by the user.
		$is_page = is_singular() || is_archive() || is_search();

		if ( is_404() || ! $is_page ) {
			return;
		}

		// Don't cleanup if user just removed an item (undo link is being displayed).
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['removed_item'] ) ) {
			return;
		}

		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['undo_item'] ) ) {
			return;
		}

		WC()->session->set( 'removed_cart_contents', null );
		$this->cart->set_removed_cart_contents( array() );
	}
}

Current_dir [ WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
abstracts
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
admin
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
blocks
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
cli
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
customizer
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
data-stores
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
emails
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
export
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
gateways
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
import
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
integrations
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
interfaces
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
legacy
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
libraries
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
log-handlers
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
payment-tokens
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
product-usage
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
queue
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
react-admin
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
rest-api
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
shipping
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
shortcodes
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
theme-support
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
tracks
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
traits
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
walkers
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
wccom-site
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
widgets
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
.htaccess
0.124 KB
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0444
class-wc-ajax.php
131.443 KB
13 Apr 2026 5.14 PM
raydofqv / raydofqv
0644
class-wc-auth.php
12.69 KB
30 Jul 2024 7.31 PM
raydofqv / raydofqv
0644
class-wc-autoloader.php
5.268 KB
6 Oct 2025 5.56 PM
raydofqv / raydofqv
0644
class-wc-background-emailer.php
4.575 KB
20 Aug 2020 11.18 PM
raydofqv / raydofqv
0644
class-wc-background-updater.php
3.452 KB
20 Aug 2020 11.18 PM
raydofqv / raydofqv
0644
class-wc-brands-brand-settings-manager.php
1.783 KB
23 Sep 2024 8.44 PM
raydofqv / raydofqv
0644
class-wc-brands-coupons.php
6.894 KB
21 Jan 2025 6.53 PM
raydofqv / raydofqv
0644
class-wc-brands.php
34.8 KB
19 Jan 2026 2.46 PM
raydofqv / raydofqv
0644
class-wc-breadcrumb.php
10.41 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-cache-helper.php
12.693 KB
6 Oct 2025 5.56 PM
raydofqv / raydofqv
0644
class-wc-cart-fees.php
3.367 KB
26 Sep 2023 9.42 PM
raydofqv / raydofqv
0644
class-wc-cart-session.php
25.366 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-cart-totals.php
28.479 KB
29 Jul 2025 12.34 PM
raydofqv / raydofqv
0644
class-wc-cart.php
75.572 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-checkout.php
50.146 KB
12 Mar 2026 8.10 PM
raydofqv / raydofqv
0644
class-wc-cli.php
3.339 KB
1 Sep 2025 11.44 PM
raydofqv / raydofqv
0644
class-wc-comments.php
23.077 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-countries.php
50.665 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-coupon.php
43.867 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-customer-download-log.php
3.371 KB
20 Aug 2020 11.18 PM
raydofqv / raydofqv
0644
class-wc-customer-download.php
10.339 KB
30 Jul 2024 7.31 PM
raydofqv / raydofqv
0644
class-wc-customer.php
33.203 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-data-exception.php
1.29 KB
23 May 2018 7.30 PM
raydofqv / raydofqv
0644
class-wc-data-store.php
6.594 KB
19 Oct 2022 12.34 AM
raydofqv / raydofqv
0644
class-wc-datetime.php
2.256 KB
20 Apr 2022 6.50 AM
raydofqv / raydofqv
0644
class-wc-deprecated-action-hooks.php
6.588 KB
27 Feb 2024 6.59 PM
raydofqv / raydofqv
0644
class-wc-deprecated-filter-hooks.php
7.342 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-discounts.php
36.644 KB
29 Jul 2025 12.34 PM
raydofqv / raydofqv
0644
class-wc-download-handler.php
28.372 KB
18 Dec 2024 10.19 PM
raydofqv / raydofqv
0644
class-wc-emails.php
39.301 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-embed.php
4.24 KB
21 Jan 2025 6.53 PM
raydofqv / raydofqv
0644
class-wc-form-handler.php
48.171 KB
9 Mar 2026 4.07 PM
raydofqv / raydofqv
0644
class-wc-frontend-scripts.php
34.36 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-geo-ip.php
30.429 KB
6 Oct 2025 5.56 PM
raydofqv / raydofqv
0644
class-wc-geolite-integration.php
1.988 KB
16 Jan 2020 6.10 AM
raydofqv / raydofqv
0644
class-wc-geolocation.php
11.343 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-https.php
4.335 KB
20 Jun 2023 11.45 PM
raydofqv / raydofqv
0644
class-wc-install.php
116.228 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-integrations.php
1.277 KB
20 Aug 2020 11.18 PM
raydofqv / raydofqv
0644
class-wc-log-levels.php
3.898 KB
30 Jan 2024 11.24 PM
raydofqv / raydofqv
0644
class-wc-logger.php
9.413 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-meta-data.php
2.207 KB
20 Apr 2022 6.50 AM
raydofqv / raydofqv
0644
class-wc-order-factory.php
8.741 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-order-item-coupon.php
4.077 KB
22 Dec 2021 12.24 AM
raydofqv / raydofqv
0644
class-wc-order-item-fee.php
9.988 KB
19 Jan 2026 2.46 PM
raydofqv / raydofqv
0644
class-wc-order-item-meta.php
5.803 KB
22 Dec 2021 12.24 AM
raydofqv / raydofqv
0644
class-wc-order-item-product.php
17.541 KB
19 Jan 2026 2.46 PM
raydofqv / raydofqv
0644
class-wc-order-item-shipping.php
9.585 KB
19 Jan 2026 2.46 PM
raydofqv / raydofqv
0644
class-wc-order-item-tax.php
6.488 KB
22 Dec 2021 12.24 AM
raydofqv / raydofqv
0644
class-wc-order-item.php
21.394 KB
19 Jan 2026 2.46 PM
raydofqv / raydofqv
0644
class-wc-order-query.php
2.552 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-order-refund.php
5.991 KB
12 May 2025 9.07 PM
raydofqv / raydofqv
0644
class-wc-order.php
77.562 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-payment-gateways.php
14.259 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-payment-tokens.php
6.24 KB
23 Nov 2022 5.58 AM
raydofqv / raydofqv
0644
class-wc-post-data.php
38.688 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-post-types.php
32.891 KB
19 Jan 2026 2.46 PM
raydofqv / raydofqv
0644
class-wc-privacy-background-process.php
1.79 KB
3 Mar 2025 10.28 PM
raydofqv / raydofqv
0644
class-wc-privacy-erasers.php
13.614 KB
1 Sep 2025 11.44 PM
raydofqv / raydofqv
0644
class-wc-privacy-exporters.php
14.691 KB
28 Jul 2021 4.11 AM
raydofqv / raydofqv
0644
class-wc-privacy.php
17.216 KB
23 Jun 2025 7.46 PM
raydofqv / raydofqv
0644
class-wc-product-attribute.php
7.868 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-product-download.php
13.178 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-product-external.php
4.984 KB
3 Mar 2025 10.28 PM
raydofqv / raydofqv
0644
class-wc-product-factory.php
4.588 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-product-grouped.php
6.811 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-product-query.php
2.273 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-product-simple.php
2.7 KB
29 Jul 2025 12.34 PM
raydofqv / raydofqv
0644
class-wc-product-variable.php
23.764 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-product-variation.php
20.177 KB
12 May 2025 9.07 PM
raydofqv / raydofqv
0644
class-wc-query.php
33.495 KB
10 Feb 2026 7.22 PM
raydofqv / raydofqv
0644
class-wc-rate-limiter.php
4.004 KB
1 Dec 2021 4.23 AM
raydofqv / raydofqv
0644
class-wc-regenerate-images-request.php
7.737 KB
25 Jan 2023 3.19 AM
raydofqv / raydofqv
0644
class-wc-regenerate-images.php
15.436 KB
25 Jun 2024 9.17 PM
raydofqv / raydofqv
0644
class-wc-register-wp-admin-settings.php
5.05 KB
22 Jun 2021 3.24 PM
raydofqv / raydofqv
0644
class-wc-rest-authentication.php
21.551 KB
25 Jun 2024 9.17 PM
raydofqv / raydofqv
0644
class-wc-rest-exception.php
0.27 KB
23 Sep 2020 1.16 AM
raydofqv / raydofqv
0644
class-wc-session-handler.php
24.572 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-shipping-rate.php
9.342 KB
23 Jun 2025 7.46 PM
raydofqv / raydofqv
0644
class-wc-shipping-zone.php
13.078 KB
23 Sep 2020 1.16 AM
raydofqv / raydofqv
0644
class-wc-shipping-zones.php
4.995 KB
24 Nov 2025 11.10 PM
raydofqv / raydofqv
0644
class-wc-shipping.php
13.058 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
class-wc-shortcodes.php
18.822 KB
21 Jan 2025 6.53 PM
raydofqv / raydofqv
0644
class-wc-structured-data.php
24.425 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-tax.php
39.74 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
class-wc-template-loader.php
20.421 KB
12 Nov 2025 6.35 PM
raydofqv / raydofqv
0644
class-wc-tracker.php
51.495 KB
6 Oct 2025 5.56 PM
raydofqv / raydofqv
0644
class-wc-validation.php
5.79 KB
28 May 2024 2.28 PM
raydofqv / raydofqv
0644
class-wc-webhook.php
30.085 KB
6 Oct 2025 5.56 PM
raydofqv / raydofqv
0644
class-woocommerce.php
62.318 KB
14 Apr 2026 4.01 PM
raydofqv / raydofqv
0644
wc-account-functions.php
14.146 KB
24 Nov 2025 11.10 PM
raydofqv / raydofqv
0644
wc-attribute-functions.php
21.853 KB
1 Sep 2025 11.44 PM
raydofqv / raydofqv
0644
wc-brands-functions.php
4.17 KB
23 Sep 2024 8.44 PM
raydofqv / raydofqv
0644
wc-cart-functions.php
20.809 KB
19 Jan 2026 2.46 PM
raydofqv / raydofqv
0644
wc-conditional-functions.php
15.529 KB
29 Jul 2025 12.34 PM
raydofqv / raydofqv
0644
wc-core-functions.php
78.714 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
wc-coupon-functions.php
5.564 KB
19 Jan 2026 2.46 PM
raydofqv / raydofqv
0644
wc-deprecated-functions.php
39.776 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
wc-formatting-functions.php
49.896 KB
24 Nov 2025 11.10 PM
raydofqv / raydofqv
0644
wc-interactivity-api-functions.php
2.167 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
wc-notice-functions.php
8.492 KB
19 Jan 2026 2.46 PM
raydofqv / raydofqv
0644
wc-order-functions.php
44.009 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
wc-order-item-functions.php
5.032 KB
25 Jan 2023 3.19 AM
raydofqv / raydofqv
0644
wc-order-step-logger-functions.php
5.971 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
wc-page-functions.php
9.431 KB
23 Sep 2024 8.44 PM
raydofqv / raydofqv
0644
wc-product-functions.php
67.375 KB
23 Feb 2026 5.58 PM
raydofqv / raydofqv
0644
wc-rest-functions.php
13.934 KB
24 Nov 2025 11.10 PM
raydofqv / raydofqv
0644
wc-stock-functions.php
17.433 KB
24 Nov 2025 11.10 PM
raydofqv / raydofqv
0644
wc-template-functions.php
142.066 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
wc-template-hooks.php
12.843 KB
1 Sep 2025 11.44 PM
raydofqv / raydofqv
0644
wc-term-functions.php
24.568 KB
24 Nov 2025 11.10 PM
raydofqv / raydofqv
0644
wc-update-functions.php
102.38 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
wc-user-functions.php
35.349 KB
30 Mar 2026 5.12 PM
raydofqv / raydofqv
0644
wc-webhook-functions.php
5.767 KB
25 Jun 2024 9.17 PM
raydofqv / raydofqv
0644
wc-widget-functions.php
2.015 KB
20 Aug 2020 11.18 PM
raydofqv / raydofqv
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF Static GIF