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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-cart-session.php
woocommerce / includes Last commit date
abstracts 8 years ago admin 8 years ago api 8 years ago cli 8 years ago customizer 8 years ago data-stores 8 years ago emails 8 years ago export 8 years ago gateways 8 years ago import 8 years ago interfaces 8 years ago legacy 8 years ago libraries 8 years ago log-handlers 8 years ago payment-tokens 9 years ago shipping 8 years ago shortcodes 8 years ago theme-support 8 years ago walkers 8 years ago widgets 8 years ago class-wc-ajax.php 8 years ago class-wc-api.php 8 years ago class-wc-auth.php 8 years ago class-wc-autoloader.php 8 years ago class-wc-background-emailer.php 8 years ago class-wc-background-updater.php 8 years ago class-wc-breadcrumb.php 8 years ago class-wc-cache-helper.php 8 years ago class-wc-cart-fees.php 8 years ago class-wc-cart-session.php 8 years ago class-wc-cart-totals.php 8 years ago class-wc-cart.php 8 years ago class-wc-checkout.php 8 years ago class-wc-cli.php 9 years ago class-wc-comments.php 8 years ago class-wc-countries.php 8 years ago class-wc-coupon.php 8 years ago class-wc-customer-download-log.php 8 years ago class-wc-customer-download.php 8 years ago class-wc-customer.php 8 years ago class-wc-data-exception.php 9 years ago class-wc-data-store.php 8 years ago class-wc-datetime.php 8 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 8 years ago class-wc-discounts.php 8 years ago class-wc-download-handler.php 8 years ago class-wc-emails.php 8 years ago class-wc-embed.php 9 years ago class-wc-form-handler.php 8 years ago class-wc-frontend-scripts.php 8 years ago class-wc-geo-ip.php 9 years ago class-wc-geolocation.php 8 years ago class-wc-https.php 9 years ago class-wc-install.php 8 years ago class-wc-integrations.php 9 years ago class-wc-log-levels.php 9 years ago class-wc-logger.php 8 years ago class-wc-meta-data.php 8 years ago class-wc-order-factory.php 8 years ago class-wc-order-item-coupon.php 8 years ago class-wc-order-item-fee.php 8 years ago class-wc-order-item-meta.php 8 years ago class-wc-order-item-product.php 8 years ago class-wc-order-item-shipping.php 8 years ago class-wc-order-item-tax.php 8 years ago class-wc-order-item.php 8 years ago class-wc-order-query.php 8 years ago class-wc-order-refund.php 9 years ago class-wc-order.php 8 years ago class-wc-payment-gateways.php 8 years ago class-wc-payment-tokens.php 9 years ago class-wc-post-data.php 8 years ago class-wc-post-types.php 8 years ago class-wc-product-attribute.php 8 years ago class-wc-product-download.php 8 years ago class-wc-product-external.php 8 years ago class-wc-product-factory.php 9 years ago class-wc-product-grouped.php 8 years ago class-wc-product-query.php 8 years ago class-wc-product-simple.php 8 years ago class-wc-product-variable.php 8 years ago class-wc-product-variation.php 8 years ago class-wc-query.php 8 years ago class-wc-regenerate-images-request.php 8 years ago class-wc-regenerate-images.php 8 years ago class-wc-register-wp-admin-settings.php 9 years ago class-wc-session-handler.php 8 years ago class-wc-shipping-rate.php 8 years ago class-wc-shipping-zone.php 8 years ago class-wc-shipping-zones.php 8 years ago class-wc-shipping.php 8 years ago class-wc-shortcodes.php 8 years ago class-wc-structured-data.php 8 years ago class-wc-tax.php 8 years ago class-wc-template-loader.php 8 years ago class-wc-tracker.php 8 years ago class-wc-validation.php 8 years ago class-wc-webhook.php 8 years ago class-woocommerce.php 8 years ago wc-account-functions.php 8 years ago wc-attribute-functions.php 8 years ago wc-cart-functions.php 8 years ago wc-conditional-functions.php 8 years ago wc-core-functions.php 8 years ago wc-coupon-functions.php 9 years ago wc-deprecated-functions.php 8 years ago wc-formatting-functions.php 8 years ago wc-notice-functions.php 8 years ago wc-order-functions.php 8 years ago wc-order-item-functions.php 9 years ago wc-page-functions.php 8 years ago wc-product-functions.php 8 years ago wc-rest-functions.php 8 years ago wc-stock-functions.php 8 years ago wc-template-functions.php 8 years ago wc-template-hooks.php 8 years ago wc-term-functions.php 8 years ago wc-update-functions.php 8 years ago wc-user-functions.php 8 years ago wc-webhook-functions.php 8 years ago wc-widget-functions.php 8 years ago
class-wc-cart-session.php
220 lines
1 <?php
2 /**
3 * Cart session handling class.
4 *
5 * @author Automattic
6 * @package WooCommerce/Classes
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * WC_Cart_Session class.
15 *
16 * @since 3.2.0
17 */
18 final class WC_Cart_Session {
19
20 /**
21 * Reference to cart object.
22 *
23 * @since 3.2.0
24 * @var WC_Cart
25 */
26 protected $cart;
27
28 /**
29 * Sets up the items provided, and calculate totals.
30 *
31 * @since 3.2.0
32 * @throws Exception If missing WC_Cart object.
33 * @param WC_Cart $cart Cart object to calculate totals for.
34 */
35 public function __construct( &$cart ) {
36 if ( ! is_a( $cart, 'WC_Cart' ) ) {
37 throw new Exception( 'A valid WC_Cart object is required' );
38 }
39
40 $this->cart = $cart;
41 }
42
43 /**
44 * Register methods for this object on the appropriate WordPress hooks.
45 */
46 public function init() {
47 add_action( 'wp_loaded', array( $this, 'get_cart_from_session' ) );
48 add_action( 'woocommerce_cart_emptied', array( $this, 'destroy_cart_session' ) );
49 add_action( 'wp', array( $this, 'maybe_set_cart_cookies' ), 99 );
50 add_action( 'shutdown', array( $this, 'maybe_set_cart_cookies' ), 0 );
51 add_action( 'woocommerce_add_to_cart', array( $this, 'maybe_set_cart_cookies' ) );
52 add_action( 'woocommerce_after_calculate_totals', array( $this, 'set_session' ) );
53 add_action( 'woocommerce_cart_loaded_from_session', array( $this, 'set_session' ) );
54 add_action( 'woocommerce_removed_coupon', array( $this, 'set_session' ) );
55 add_action( 'woocommerce_cart_updated', array( $this, 'persistent_cart_update' ) );
56 }
57
58 /**
59 * Get the cart data from the PHP session and store it in class variables.
60 *
61 * @since 3.2.0
62 */
63 public function get_cart_from_session() {
64 $update_cart_session = false;
65 $totals = WC()->session->get( 'cart_totals', null );
66 $cart = WC()->session->get( 'cart', null );
67
68 $this->cart->set_totals( $totals );
69 $this->cart->set_applied_coupons( WC()->session->get( 'applied_coupons', array() ) );
70 $this->cart->set_coupon_discount_totals( WC()->session->get( 'coupon_discount_totals', array() ) );
71 $this->cart->set_coupon_discount_tax_totals( WC()->session->get( 'coupon_discount_tax_totals', array() ) );
72 $this->cart->set_removed_cart_contents( WC()->session->get( 'removed_cart_contents', array() ) );
73
74 if ( is_null( $cart ) && ( $saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true ) ) ) { // @codingStandardsIgnoreLine
75 $cart = $saved_cart['cart'];
76 $update_cart_session = true;
77 } elseif ( is_null( $cart ) ) {
78 $cart = array();
79 } elseif ( is_array( $cart ) && ( $saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true ) ) ) { // @codingStandardsIgnoreLine
80 $cart = array_merge( $saved_cart['cart'], $cart );
81 $update_cart_session = true;
82 }
83
84 if ( is_array( $cart ) ) {
85 $cart_contents = array();
86
87 update_meta_cache( 'post', wp_list_pluck( $cart, 'product_id' ) ); // Prime meta cache to reduce future queries.
88 update_object_term_cache( wp_list_pluck( $cart, 'product_id' ), 'product' );
89
90 foreach ( $cart as $key => $values ) {
91 $product = wc_get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );
92
93 if ( ! empty( $product ) && $product->exists() && $values['quantity'] > 0 ) {
94
95 if ( ! $product->is_purchasable() ) {
96 $update_cart_session = true; // Flag to indicate the stored cart should be updated.
97 /* translators: %s: product name */
98 wc_add_notice( 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() ), 'error' );
99 do_action( 'woocommerce_remove_cart_item_from_session', $key, $values );
100
101 } else {
102 // Put session data into array. Run through filter so other plugins can load their own session data.
103 $session_data = array_merge( $values, array(
104 'data' => $product,
105 ) );
106 $cart_contents[ $key ] = apply_filters( 'woocommerce_get_cart_item_from_session', $session_data, $values, $key );
107
108 // Add to cart right away so the product is visible in woocommerce_get_cart_item_from_session hook.
109 $this->cart->set_cart_contents( $cart_contents );
110 }
111 }
112 }
113 }
114
115 do_action( 'woocommerce_cart_loaded_from_session', $this->cart );
116
117 if ( $update_cart_session || is_null( WC()->session->get( 'cart_totals', null ) ) ) {
118 WC()->session->set( 'cart', $this->get_cart_for_session() );
119 $this->cart->calculate_totals();
120 }
121 }
122
123 /**
124 * Destroy cart session data.
125 *
126 * @since 3.2.0
127 */
128 public function destroy_cart_session() {
129 WC()->session->set( 'cart', null );
130 WC()->session->set( 'cart_totals', null );
131 WC()->session->set( 'applied_coupons', null );
132 WC()->session->set( 'coupon_discount_totals', null );
133 WC()->session->set( 'coupon_discount_tax_totals', null );
134 WC()->session->set( 'removed_cart_contents', null );
135 WC()->session->set( 'order_awaiting_payment', null );
136 }
137
138 /**
139 * Will set cart cookies if needed and when possible.
140 *
141 * @since 3.2.0
142 */
143 public function maybe_set_cart_cookies() {
144 if ( ! headers_sent() && did_action( 'wp_loaded' ) ) {
145 if ( ! $this->cart->is_empty() ) {
146 $this->set_cart_cookies( true );
147 } elseif ( isset( $_COOKIE['woocommerce_items_in_cart'] ) ) {
148 $this->set_cart_cookies( false );
149 }
150 }
151 }
152
153 /**
154 * Sets the php session data for the cart and coupons.
155 */
156 public function set_session() {
157 WC()->session->set( 'cart', $this->get_cart_for_session() );
158 WC()->session->set( 'cart_totals', $this->cart->get_totals() );
159 WC()->session->set( 'applied_coupons', $this->cart->get_applied_coupons() );
160 WC()->session->set( 'coupon_discount_totals', $this->cart->get_coupon_discount_totals() );
161 WC()->session->set( 'coupon_discount_tax_totals', $this->cart->get_coupon_discount_tax_totals() );
162 WC()->session->set( 'removed_cart_contents', $this->cart->get_removed_cart_contents() );
163
164 do_action( 'woocommerce_cart_updated' );
165 }
166
167 /**
168 * Returns the contents of the cart in an array without the 'data' element.
169 *
170 * @return array contents of the cart
171 */
172 public function get_cart_for_session() {
173 $cart_session = array();
174
175 foreach ( $this->cart->get_cart() as $key => $values ) {
176 $cart_session[ $key ] = $values;
177 unset( $cart_session[ $key ]['data'] ); // Unset product object.
178 }
179
180 return $cart_session;
181 }
182
183 /**
184 * Save the persistent cart when the cart is updated.
185 */
186 public function persistent_cart_update() {
187 if ( get_current_user_id() ) {
188 update_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), array(
189 'cart' => $this->get_cart_for_session(),
190 ) );
191 }
192 }
193
194 /**
195 * Delete the persistent cart permanently.
196 */
197 public function persistent_cart_destroy() {
198 if ( get_current_user_id() ) {
199 delete_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id() );
200 }
201 }
202
203 /**
204 * Set cart hash cookie and items in cart.
205 *
206 * @access private
207 * @param bool $set Should cookies be set (true) or unset.
208 */
209 private function set_cart_cookies( $set = true ) {
210 if ( $set ) {
211 wc_setcookie( 'woocommerce_items_in_cart', 1 );
212 wc_setcookie( 'woocommerce_cart_hash', md5( wp_json_encode( $this->get_cart_for_session() ) ) );
213 } elseif ( isset( $_COOKIE['woocommerce_items_in_cart'] ) ) {
214 wc_setcookie( 'woocommerce_items_in_cart', 0, time() - HOUR_IN_SECONDS );
215 wc_setcookie( 'woocommerce_cart_hash', '', time() - HOUR_IN_SECONDS );
216 }
217 do_action( 'woocommerce_set_cart_cookies', $set );
218 }
219 }
220