From 671ae32e580d7124e72b292c031d6b12d0116d12 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Tue, 17 May 2016 16:38:08 -0700 Subject: [PATCH] Use print_r() to stringify cart session Instead of json_encode(), because json_encode() takes types into account, meaning numbers may end up being represented in the encoded JSON as a string, e.g. "1" instead of 1, which can lead to the md5() being different between requests. This issue surfaces when creating a cart hash in a different request to the request to pay for the order, because after adding line items to the cart, the items quantity will be encoded with json_encode() as an int, but when encoding them in a different request, where they are coming from the database, they will be encoded as a string. --- includes/class-wc-checkout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-checkout.php b/includes/class-wc-checkout.php index 6e030441fd00..253fb2a38694 100644 --- a/includes/class-wc-checkout.php +++ b/includes/class-wc-checkout.php @@ -184,7 +184,7 @@ public function create_order() { 'status' => apply_filters( 'woocommerce_default_order_status', 'pending' ), 'customer_id' => $this->customer_id, 'customer_note' => isset( $this->posted['order_comments'] ) ? $this->posted['order_comments'] : '', - 'cart_hash' => md5( json_encode( WC()->cart->get_cart_for_session() ) . WC()->cart->total ), + 'cart_hash' => md5( print_r( WC()->cart->get_cart_for_session(), true ) . WC()->cart->total ), 'created_via' => 'checkout' );