/var/www/html_us/wp-content/plugins/woocommerce/includes/wc-cart-functions.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<?php
/**
 * WooCommerce Cart Functions
 *
 * Functions for cart specific things.
 *
 * @package WooCommerce\Functions
 * @version 2.5.0
 */

use Automattic\Jetpack\Constants;
use 
Automattic\WooCommerce\Enums\OrderStatus;
use 
Automattic\WooCommerce\Enums\ProductType;
use 
Automattic\WooCommerce\StoreApi\Utilities\LocalPickupUtils;

defined'ABSPATH' ) || exit;

/**
 * Prevent password protected products being added to the cart.
 *
 * @param  bool $passed     Validation.
 * @param  int  $product_id Product ID.
 * @return bool
 */
function wc_protected_product_add_to_cart$passed$product_id ) {
    if ( 
post_password_required$product_id ) ) {
        
$passed false;
        
wc_add_notice__'This product is protected and cannot be purchased.''woocommerce' ), 'error' );
    }
    return 
$passed;
}
add_filter'woocommerce_add_to_cart_validation''wc_protected_product_add_to_cart'10);

/**
 * Clears the cart session when called.
 */
function wc_empty_cart() {
    if ( ! isset( 
WC()->cart ) || '' === WC()->cart ) {
        
WC()->cart = new WC_Cart();
    }
    
WC()->cart->empty_cartfalse );
}

/**
 * Load the persistent cart.
 *
 * @param string  $user_login User login.
 * @param WP_User $user       User data.
 * @deprecated 2.3
 */
function wc_load_persistent_cart$user_login$user ) {
    if ( ! 
$user || ! apply_filters'woocommerce_persistent_cart_enabled'true ) ) {
        return;
    }

    
$saved_cart get_user_meta$user->ID'_woocommerce_persistent_cart_' get_current_blog_id(), true );

    if ( ! 
$saved_cart ) {
        return;
    }

    
$cart WC()->session->cart;

    if ( empty( 
$cart ) || ! is_array$cart ) || === count$cart ) ) {
        
WC()->session->cart $saved_cart['cart'];
    }
}

/**
 * Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
 *
 * Do not use for redirects, use {@see wp_get_referer()} instead.
 *
 * @since 2.6.1
 * @return string|false Referer URL on success, false on failure.
 */
function wc_get_raw_referer() {
    if ( 
function_exists'wp_get_raw_referer' ) ) {
        return 
wp_get_raw_referer();
    }

    if ( ! empty( 
$_REQUEST['_wp_http_referer'] ) ) { // WPCS: input var ok, CSRF ok.
        
return wp_unslash$_REQUEST['_wp_http_referer'] ); // WPCS: input var ok, CSRF ok, sanitization ok.
    
} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { // WPCS: input var ok, CSRF ok.
        
return wp_unslash$_SERVER['HTTP_REFERER'] ); // WPCS: input var ok, CSRF ok, sanitization ok.
    
}

    return 
false;
}

/**
 * Add to cart messages.
 *
 * @param int|array $products Product ID list or single product ID.
 * @param bool      $show_qty Should quantities be shown? Added in 2.6.0.
 * @param bool      $return   Return message rather than add it.
 *
 * @return mixed
 */
function wc_add_to_cart_message$products$show_qty false$return false ) {
    
$titles = array();
    
$count  0;

    if ( ! 
is_array$products ) ) {
        
$products = array( $products => );
        
$show_qty false;
    }

    if ( ! 
$show_qty ) {
        
$products array_fill_keysarray_keys$products ), );
    }

    
$product_id null;
    foreach ( 
$products as $product_id => $qty ) {
        
/* translators: %s: product name */
        
$titles[] = apply_filters'woocommerce_add_to_cart_qty_html', ( $qty absint$qty ) . ' &times; ' '' ), $product_id ) . apply_filters'woocommerce_add_to_cart_item_name_in_quotes'sprintf_x'&ldquo;%s&rdquo;''Item name in quotes''woocommerce' ), strip_tagsget_the_title$product_id ) ) ), $product_id );
        
$count   += $qty;
    }

    
$titles array_filter$titles );
    
/* translators: %s: product name */
    
$added_text sprintf_n'%s has been added to your cart.''%s have been added to your cart.'$count'woocommerce' ), wc_format_list_of_items$titles ) );

    
// Output success messages.
    
$wp_button_class wc_wp_theme_get_element_class_name'button' ) ? ' ' wc_wp_theme_get_element_class_name'button' ) : '';
    if ( 
'yes' === get_option'woocommerce_cart_redirect_after_add' ) ) {
        
$return_to apply_filters'woocommerce_continue_shopping_redirect'wc_get_raw_referer() ? wp_validate_redirectwc_get_raw_referer(), false ) : wc_get_page_permalink'shop' ) );
        
$message   sprintf'%s <a href="%s" class="button wc-forward%s">%s</a>'esc_html$added_text ), esc_url$return_to ), esc_attr$wp_button_class ), esc_html__'Continue shopping''woocommerce' ) );
    } else {
        
$message sprintf'%s <a href="%s" class="button wc-forward%s">%s</a>'esc_html$added_text ), esc_urlwc_get_cart_url() ), esc_attr$wp_button_class ), esc_html__'View cart''woocommerce' ) );
    }

    if ( 
has_filter'wc_add_to_cart_message' ) ) {
        
wc_deprecated_function'The wc_add_to_cart_message filter''3.0''wc_add_to_cart_message_html' );
        
$message apply_filters'wc_add_to_cart_message'$message$product_id );
    }

    
$message apply_filters'wc_add_to_cart_message_html'$message$products$show_qty );

    if ( 
$return ) {
        return 
$message;
    } else {
        
wc_add_notice$messageapply_filters'woocommerce_add_to_cart_notice_type''success' ) );
    }
}

/**
 * Comma separate a list of item names, and replace final comma with 'and'.
 *
 * @param  array $items Cart items.
 * @return string
 */
function wc_format_list_of_items$items ) {
    
$item_string '';

    foreach ( 
$items as $key => $item ) {
        
$item_string .= $item;

        if ( 
count$items ) === $key ) {
            
$item_string .= ' ' __'and''woocommerce' ) . ' ';
        } elseif ( 
count$items ) !== $key ) {
            
$item_string .= ', ';
        }
    }

    return 
$item_string;
}

/**
 * Clear cart after payment.
 */
function wc_clear_cart_after_payment() {
    global 
$wp;

    
$should_clear_cart_after_payment false;
    
$after_payment                   false;

    
// If the order has been received, clear the cart.
    
if ( ! empty( $wp->query_vars['order-received'] ) ) {

        
$order_id  absint$wp->query_vars['order-received'] );
        
$order_key = isset( $_GET['key'] ) ? wc_cleanwp_unslash$_GET['key'] ) ) : ''// WPCS: input var ok, CSRF ok.

        
if ( $order_id ) {
            
$order wc_get_order$order_id );

            if ( 
$order instanceof WC_Order && hash_equals$order->get_order_key(), $order_key ) ) {
                
$should_clear_cart_after_payment true;
                
$after_payment                   true;
            }
        }
    }

    
// If the order is awaiting payment, and we haven't already decided to clear the cart, check the order status.
    
if ( is_objectWC()->session ) && WC()->session->order_awaiting_payment && ! $should_clear_cart_after_payment ) {
        
$order wc_get_orderWC()->session->order_awaiting_payment );

        if ( 
$order instanceof WC_Order && $order->get_id() > ) {
            
// If the order status is neither pending, failed, nor cancelled, the order must have gone through.
            
$should_clear_cart_after_payment = ! $order->has_status( array( OrderStatus::FAILEDOrderStatus::PENDINGOrderStatus::CANCELLED ) );
            
$after_payment                   true;
        }
    }

    
// If it doesn't look like a payment happened, bail early.
    
if ( ! $after_payment ) {
        return;
    }

    
/**
     * Determine whether the cart should be cleared after payment.
     *
     * @since 9.3.0
     * @param bool $should_clear_cart_after_payment Whether the cart should be cleared after payment.
     */
    
$should_clear_cart_after_payment apply_filters'woocommerce_should_clear_cart_after_payment'$should_clear_cart_after_payment );

    if ( 
$should_clear_cart_after_payment ) {
        
WC()->cart->empty_cart();
    }
}
add_action'template_redirect''wc_clear_cart_after_payment'20 );

/**
 * Get the subtotal.
 */
function wc_cart_totals_subtotal_html() {
    echo 
WC()->cart->get_cart_subtotal(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
 * Get shipping methods.
 */
function wc_cart_totals_shipping_html() {
    
$packages WC()->shipping()->get_packages();
    
$first    true;

    foreach ( 
$packages as $i => $package ) {
        
$chosen_method = isset( WC()->session->chosen_shipping_methods$i ] ) ? WC()->session->chosen_shipping_methods$i ] : '';
        
$product_names = array();

        if ( 
count$packages ) > ) {
            foreach ( 
$package['contents'] as $item_id => $values ) {
                
$product_names$item_id ] = $values['data']->get_name() . ' &times;' $values['quantity'];
            }
            
$product_names apply_filters'woocommerce_shipping_package_details_array'$product_names$package );
        }

        
wc_get_template(
            
'cart/cart-shipping.php',
            array(
                
'package'                  => $package,
                
'available_methods'        => $package['rates'],
                
'show_package_details'     => count$packages ) > 1,
                
'show_shipping_calculator' => is_cart() && apply_filters'woocommerce_shipping_show_shipping_calculator'$first$i$package ),
                
'package_details'          => implode', '$product_names ),
                
/* translators: %d: shipping package number */
                
'package_name'             => apply_filters'woocommerce_shipping_package_name', ( ( $i ) > ) ? sprintf_x'Shipping %d''shipping packages''woocommerce' ), ( $i ) ) : _x'Shipping''shipping packages''woocommerce' ), $i$package ),
                
'index'                    => $i,
                
'chosen_method'            => $chosen_method,
                
'formatted_destination'    => WC()->countries->get_formatted_address$package['destination'], ', ' ),
                
'has_calculated_shipping'  => WC()->customer->has_calculated_shipping(),
            )
        );

        
$first false;
    }
}

/**
 * Get taxes total.
 */
function wc_cart_totals_taxes_total_html() {
    echo 
apply_filters'woocommerce_cart_totals_taxes_total_html'wc_priceWC()->cart->get_taxes_total() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
 * Get a coupon label.
 *
 * @param string|WC_Coupon $coupon Coupon data or code.
 * @param bool             $echo   Echo or return.
 *
 * @return string
 */
function wc_cart_totals_coupon_label$coupon$echo true ) {
    if ( 
is_string$coupon ) ) {
        
$coupon = new WC_Coupon$coupon );
    }

    
/* translators: %s: coupon code */
    
$label apply_filters'woocommerce_cart_totals_coupon_label'sprintfesc_html__'Coupon: %s''woocommerce' ), $coupon->get_code() ), $coupon );

    if ( 
$echo ) {
        echo 
$label// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    
} else {
        return 
$label;
    }
}

/**
 * Get coupon display HTML.
 *
 * @param string|WC_Coupon $coupon Coupon data or code.
 */
function wc_cart_totals_coupon_html$coupon ) {
    if ( 
is_string$coupon ) ) {
        
$coupon = new WC_Coupon$coupon );
    }

    
$amount               WC()->cart->get_coupon_discount_amount$coupon->get_code(), WC()->cart->display_cart_ex_tax );
    
$discount_amount_html '-' wc_price$amount );

    if ( 
$coupon->get_free_shipping() && empty( $amount ) ) {
        
$discount_amount_html __'Free shipping coupon''woocommerce' );
    }

    
$discount_amount_html apply_filters'woocommerce_coupon_discount_amount_html'$discount_amount_html$coupon );
    
$coupon_html          $discount_amount_html ' <a href="' esc_urladd_query_arg'remove_coupon'rawurlencode$coupon->get_code() ), Constants::is_defined'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' esc_attr$coupon->get_code() ) . '">' __'[Remove]''woocommerce' ) . '</a>';

    echo 
wp_ksesapply_filters'woocommerce_cart_totals_coupon_html'$coupon_html$coupon$discount_amount_html ), array_replace_recursivewp_kses_allowed_html'post' ), array( 'a' => array( 'data-coupon' => true ) ) ) ); // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound
}

/**
 * Get order total html including inc tax if needed.
 */
function wc_cart_totals_order_total_html() {
    
$value '<strong>' WC()->cart->get_total() . '</strong> ';

    
// If prices are tax inclusive, show taxes here.
    
if ( wc_tax_enabled() && WC()->cart->display_prices_including_tax() ) {
        
$tax_string_array = array();
        
$cart_tax_totals  WC()->cart->get_tax_totals();

        if ( 
get_option'woocommerce_tax_total_display' ) === 'itemized' ) {
            foreach ( 
$cart_tax_totals as $code => $tax ) {
                
$tax_string_array[] = sprintf'%s %s'$tax->formatted_amount$tax->label );
            }
        } elseif ( ! empty( 
$cart_tax_totals ) ) {
            
$tax_string_array[] = sprintf'%s %s'wc_priceWC()->cart->get_taxes_totaltruetrue ) ), WC()->countries->tax_or_vat() );
        }

        if ( ! empty( 
$tax_string_array ) ) {
            
$taxable_address WC()->customer->get_taxable_address();
            if ( 
WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping() ) {
                
$country WC()->countries->estimated_for_prefix$taxable_address[0] ) . WC()->countries->countries$taxable_address[0] ];
                
/* translators: 1: tax amount 2: country name */
                
$tax_text wp_kses_postsprintf__'(includes %1$s estimated for %2$s)''woocommerce' ), implode', '$tax_string_array ), $country ) );
            } else {
                
/* translators: %s: tax amount */
                
$tax_text wp_kses_postsprintf__'(includes %s)''woocommerce' ), implode', '$tax_string_array ) ) );
            }

            
$value .= '<small class="includes_tax">' $tax_text '</small>';
        }
    }

    echo 
apply_filters'woocommerce_cart_totals_order_total_html'$value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
 * Get the fee value.
 *
 * @param object $fee Fee data.
 */
function wc_cart_totals_fee_html$fee ) {
    
$cart_totals_fee_html WC()->cart->display_prices_including_tax() ? wc_price$fee->total $fee->tax ) : wc_price$fee->total );

    echo 
apply_filters'woocommerce_cart_totals_fee_html'$cart_totals_fee_html$fee ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
 * Get a shipping methods full label including price.
 *
 * @param  WC_Shipping_Rate $method Shipping method rate data.
 * @return string
 */
function wc_cart_totals_shipping_method_label$method ) {
    
$label     $method->get_label();
    
$has_cost  $method->cost;
    
$hide_cost = ! $has_cost && in_array$method->get_method_id(), array( 'free_shipping''local_pickup' ), true );

    if ( 
$has_cost && ! $hide_cost ) {
        if ( 
WC()->cart->display_prices_including_tax() ) {
            
$label .= ': ' wc_price$method->cost $method->get_shipping_tax() );
            if ( 
$method->get_shipping_tax() > && ! wc_prices_include_tax() ) {
                
$label .= ' <small class="tax_label">' WC()->countries->inc_tax_or_vat() . '</small>';
            }
        } else {
            
$label .= ': ' wc_price$method->cost );
            if ( 
$method->get_shipping_tax() > && wc_prices_include_tax() ) {
                
$label .= ' <small class="tax_label">' WC()->countries->ex_tax_or_vat() . '</small>';
            }
        }
    }

    return 
apply_filters'woocommerce_cart_shipping_method_full_label'$label$method );
}

/**
 * Round discount.
 *
 * @param  double $value Amount to round.
 * @param  int    $precision DP to round.
 * @return float
 */
function wc_cart_round_discount$value$precision ) {
    return 
wc_round_discount$value$precision );
}

/**
 * Gets chosen shipping method IDs from chosen_shipping_methods session, without instance IDs.
 *
 * @since  2.6.2
 * @return string[]
 */
function wc_get_chosen_shipping_method_ids() {
    if ( ! 
is_callable( array( WC()->session'get' ) ) ) {
        return array();
    }

    
$chosen_methods WC()->session->get'chosen_shipping_methods', array() );
    
$method_ids     = array();

    foreach ( 
$chosen_methods as $chosen_method ) {
        if ( ! 
is_string$chosen_method ) ) {
            continue;
        }
        
$chosen_method explode':'$chosen_method );
        
$method_ids[]  = current$chosen_method );
    }

    return 
$method_ids;
}

/**
 * Get chosen method for package from session.
 *
 * @since  3.2.0
 * @param  int   $key Key of package.
 * @param  array $package Package data array.
 * @return string|bool Either the chosen method ID or false if nothing is chosen yet.
 */
function wc_get_chosen_shipping_method_for_package$key$package ) {
    if ( ! 
is_callable( array( WC()->session'get' ) ) ) {
        return 
false;
    }

    
$chosen_methods WC()->session->get'chosen_shipping_methods', array() );
    
$chosen_method  = isset( $chosen_methods$key ] ) ? $chosen_methods$key ] : false;
    
$changed        wc_shipping_methods_have_changed$key$package );

    
// This is deprecated but here for BW compat. Remove in 4.0.0.
    
$method_counts WC()->session->get'shipping_method_counts' );

    if ( ! empty( 
$method_counts$key ] ) ) {
        
$method_count absint$method_counts$key ] );
    } else {
        
$method_count 0;
    }

    if ( ! isset( 
$package['rates'] ) || ! is_array$package['rates'] ) ) {
        
$package['rates'] = array();
    }

    
// If not set, not available, or available methods have changed, set to the DEFAULT option.
    
if ( ! $chosen_method || $changed || ! isset( $package['rates'][ $chosen_method ] ) || count$package['rates'] ) !== $method_count ) {
        
$chosen_method          wc_get_default_shipping_method_for_package$key$package$chosen_method );
        
$chosen_methods$key ] = $chosen_method;
        
$method_counts$key ]  = count$package['rates'] );

        
WC()->session->set'chosen_shipping_methods'$chosen_methods );
        
WC()->session->set'shipping_method_counts'$method_counts );

        
/**
         * Fires when a shipping method is chosen.
         *
         * @since 3.2.0
         * @param string $chosen_method Chosen shipping method. e.g. flat_rate:1.
         */
        
do_action'woocommerce_shipping_method_chosen'$chosen_method );
    }
    return 
$chosen_method;
}

/**
 * Choose the default method for a package.
 *
 * @since  3.2.0
 * @param  int    $key Key of package.
 * @param  array  $package Package data array.
 * @param  string $chosen_method Chosen shipping method. e.g. flat_rate:1.
 * @return string
 */
function wc_get_default_shipping_method_for_package$key$package$chosen_method ) {
    
$chosen_method_id     currentexplode':'$chosen_method ) );
    
$rate_keys            array_keys$package['rates'] );
    
$chosen_method_exists in_array$chosen_method$rate_keystrue );

    
/**
     * If the customer has selected local pickup, keep it selected if it's still in the package. We don't want to auto
     * toggle between shipping and pickup even if available shipping methods are changed.
     *
     * This is important for block-based checkout where there is an explicit toggle between shipping and pickup.
     */
    
$local_pickup_method_ids LocalPickupUtils::get_local_pickup_method_ids();
    
$is_local_pickup_chosen  in_array$chosen_method_id$local_pickup_method_idstrue );

    
// Default to the first method in the package. This can be sorted in the backend by the merchant.
    
$default current$rate_keys );

    
// Default to local pickup if its chosen already.
    
if ( $chosen_method_exists && $is_local_pickup_chosen ) {
        
$default $chosen_method;

    } else {
        
// Check coupons to see if free shipping is available. If it is, we'll use that method as the default.
        
$coupons WC()->cart->get_coupons();
        foreach ( 
$coupons as $coupon ) {
            if ( 
$coupon->get_free_shipping() ) {
                foreach ( 
$rate_keys as $rate_key ) {
                    if ( 
=== stripos$rate_key'free_shipping' ) ) {
                        
$default $rate_key;
                        break;
                    }
                }
                break;
            }
        }
    }

    
/**
     * Filters the default shipping method for a package.
     *
     * @since 3.2.0
     * @param string $default Default shipping method.
     * @param array  $rates   Shipping rates.
     * @param string $chosen_method Chosen method id.
     */
    
return (string) apply_filters'woocommerce_shipping_chosen_method'$default$package['rates'], $chosen_method );
}

/**
 * See if the methods have changed since the last request.
 *
 * @since  3.2.0
 * @param  int   $key Key of package.
 * @param  array $package Package data array.
 * @return bool
 */
function wc_shipping_methods_have_changed$key$package ) {
    if ( ! 
is_callable( array( WC()->session'get' ) ) ) {
        return 
false;
    }

    
// Lookup previous methods from session.
    
$previous_shipping_methods WC()->session->get'previous_shipping_methods' );
    
// Get new and old rates.
    
$new_rates  array_keys$package['rates'] );
    
$prev_rates = isset( $previous_shipping_methods$key ] ) ? $previous_shipping_methods$key ] : false;
    
// Update session.
    
$previous_shipping_methods$key ] = $new_rates;
    
WC()->session->set'previous_shipping_methods'$previous_shipping_methods );
    return 
$new_rates !== $prev_rates;
}

/**
 * Gets a hash of important product data that when changed should cause cart items to be invalidated.
 *
 * The woocommerce_cart_item_data_to_validate filter can be used to add custom properties.
 *
 * @param WC_Product $product Product object.
 * @return string
 */
function wc_get_cart_item_data_hash$product ) {
    return 
md5(
        
wp_json_encode(
            
apply_filters(
                
'woocommerce_cart_item_data_to_validate',
                array(
                    
'type'       => $product->get_type(),
                    
'attributes' => ProductType::VARIATION === $product->get_type() ? $product->get_variation_attributes() : '',
                ),
                
$product
            
)
        )
    );
}