Skip to content

Commit

Permalink
Merge branch 'pr/21050'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Jan 31, 2019
2 parents 64c76ee + a68ed39 commit 4069411
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion includes/class-wc-ajax.php
Expand Up @@ -179,7 +179,7 @@ public static function get_refreshed_fragments() {
'div.widget_shopping_cart_content' => '<div class="widget_shopping_cart_content">' . $mini_cart . '</div>',
)
),
'cart_hash' => apply_filters( 'woocommerce_add_to_cart_hash', WC()->cart->get_cart_for_session() ? md5( json_encode( WC()->cart->get_cart_for_session() ) ) : '', WC()->cart->get_cart_for_session() ),
'cart_hash' => WC()->cart->get_cart_hash(),
);

wp_send_json( $data );
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-cart-session.php
Expand Up @@ -260,7 +260,7 @@ public function persistent_cart_destroy() {
private function set_cart_cookies( $set = true ) {
if ( $set ) {
wc_setcookie( 'woocommerce_items_in_cart', 1 );
wc_setcookie( 'woocommerce_cart_hash', md5( wp_json_encode( $this->get_cart_for_session() ) ) );
wc_setcookie( 'woocommerce_cart_hash', WC()->cart->get_cart_hash() );
} elseif ( isset( $_COOKIE['woocommerce_items_in_cart'] ) ) { // WPCS: input var ok.
wc_setcookie( 'woocommerce_items_in_cart', 0, time() - HOUR_IN_SECONDS );
wc_setcookie( 'woocommerce_cart_hash', '', time() - HOUR_IN_SECONDS );
Expand Down
14 changes: 14 additions & 0 deletions includes/class-wc-cart.php
Expand Up @@ -1954,4 +1954,18 @@ private function is_tax_displayed() {

return get_option( 'woocommerce_tax_display_cart' );
}

/**
* Returns the hash based on cart contents.
*
* @since 3.6.0
* @return string hash for cart content
*/
public function get_cart_hash() {
$cart_session = $this->session->get_cart_for_session();
$hash = $cart_session ? md5( wp_json_encode( $cart_session ) . $this->get_total( 'edit' ) ) : '';
$hash = apply_filters_deprecated( 'woocommerce_add_to_cart_hash', array( $hash, $cart_session ), '3.6.0', 'woocommerce_cart_hash' );

return apply_filters( 'woocommerce_cart_hash', $hash, $cart_session );
}
}
2 changes: 1 addition & 1 deletion includes/class-wc-checkout.php
Expand Up @@ -293,7 +293,7 @@ public function create_order( $data ) {

try {
$order_id = absint( WC()->session->get( 'order_awaiting_payment' ) );
$cart_hash = md5( wp_json_encode( wc_clean( WC()->cart->get_cart_for_session() ) ) . WC()->cart->total );
$cart_hash = WC()->cart->get_cart_hash();
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$order = $order_id ? wc_get_order( $order_id ) : null;

Expand Down

0 comments on commit 4069411

Please sign in to comment.