Merge branch 'pr/21050'

This commit is contained in:
Mike Jolley 2019-01-31 15:47:52 +00:00
commit 40694118fc
4 changed files with 17 additions and 3 deletions

View File

@ -179,7 +179,7 @@ class WC_AJAX {
'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 );

View File

@ -260,7 +260,7 @@ final class WC_Cart_Session {
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 );

View File

@ -1954,4 +1954,18 @@ class WC_Cart extends WC_Legacy_Cart {
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 );
}
}

View File

@ -293,7 +293,7 @@ class WC_Checkout {
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;