From fa4049188c23aba51466d3a5e166d785bda5dc9d Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 12 Apr 2017 12:33:24 +0100 Subject: [PATCH 001/189] Set and restore wp_query so product page functions think it's a real product page Fixes #14162 --- includes/class-wc-shortcodes.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/includes/class-wc-shortcodes.php b/includes/class-wc-shortcodes.php index a7c0c6d8992..4ca9ac0527c 100644 --- a/includes/class-wc-shortcodes.php +++ b/includes/class-wc-shortcodes.php @@ -730,19 +730,25 @@ class WC_Shortcodes { ob_start(); - while ( $single_product->have_posts() ) : - $single_product->the_post(); - wp_enqueue_script( 'wc-single-product' ); + global $wp_query; + + // Backup query object so following loops think this is a product page. + $previous_wp_query = $wp_query; + $wp_query = $single_product; + + wp_enqueue_script( 'wc-single-product' ); + + while ( $single_product->have_posts() ) { + $single_product->the_post() ?> -
- -
+ ' . ob_get_clean() . ''; From 3fe7df65150ef6974a7849009a85ed2c146bf0ec Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 12 Apr 2017 12:42:55 +0100 Subject: [PATCH 002/189] When searching, disable WC sort order Closes #14292 --- includes/class-wc-query.php | 14 +++++++++----- includes/wc-template-functions.php | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/class-wc-query.php b/includes/class-wc-query.php index 66127445711..67a2813e9ee 100644 --- a/includes/class-wc-query.php +++ b/includes/class-wc-query.php @@ -384,11 +384,15 @@ class WC_Query { */ public function product_query( $q ) { // Ordering query vars - $ordering = $this->get_catalog_ordering_args(); - $q->set( 'orderby', $ordering['orderby'] ); - $q->set( 'order', $ordering['order'] ); - if ( isset( $ordering['meta_key'] ) ) { - $q->set( 'meta_key', $ordering['meta_key'] ); + if ( ! $q->is_search() ) { + $ordering = $this->get_catalog_ordering_args(); + $q->set( 'orderby', $ordering['orderby'] ); + $q->set( 'order', $ordering['order'] ); + if ( isset( $ordering['meta_key'] ) ) { + $q->set( 'meta_key', $ordering['meta_key'] ); + } + } else { + $q->set( 'orderby', 'relevance' ); } // Query vars that affect posts shown diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 2b2e52323fb..74bcbc69676 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -787,7 +787,7 @@ if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) { function woocommerce_catalog_ordering() { global $wp_query; - if ( 1 === (int) $wp_query->found_posts || ! woocommerce_products_will_display() ) { + if ( 1 === (int) $wp_query->found_posts || ! woocommerce_products_will_display() || $wp_query->is_search() ) { return; } From f940961c6fdb1e382d671944eec7db2b0bc09cde Mon Sep 17 00:00:00 2001 From: Ninos Ego Date: Thu, 20 Apr 2017 00:55:07 +0200 Subject: [PATCH 003/189] Remove thousand seperator if dot --- includes/wc-formatting-functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/wc-formatting-functions.php b/includes/wc-formatting-functions.php index ddb326b5d3d..33c441f267f 100644 --- a/includes/wc-formatting-functions.php +++ b/includes/wc-formatting-functions.php @@ -253,10 +253,12 @@ function wc_format_refund_total( $amount ) { function wc_format_decimal( $number, $dp = false, $trim_zeros = false ) { $locale = localeconv(); $decimals = array( wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] ); + $thousands = array( wc_get_price_thousand_separator(), $locale['thousands_sep'], $locale['thousands_sep'] ); // Remove locale from string. if ( ! is_float( $number ) ) { - $number = wc_clean( str_replace( $decimals, '.', $number ) ); + $number = wc_clean( str_replace( $thousands, '', $number ) ); + $number = str_replace( $decimals, '.', $number ); $number = preg_replace( '/[^0-9\.,-]/', '', $number ); } From 928d157ba77b1c379a6c4de1879d3280d4097ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demarle?= Date: Thu, 20 Apr 2017 18:25:19 +0200 Subject: [PATCH 004/189] Add custom message for custom system status tools --- includes/api/class-wc-rest-system-status-tools-controller.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/api/class-wc-rest-system-status-tools-controller.php b/includes/api/class-wc-rest-system-status-tools-controller.php index 60e614f2b86..97f68a1c7b5 100644 --- a/includes/api/class-wc-rest-system-status-tools-controller.php +++ b/includes/api/class-wc-rest-system-status-tools-controller.php @@ -446,7 +446,9 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller { if ( isset( $tools[ $tool ]['callback'] ) ) { $callback = $tools[ $tool ]['callback']; $return = call_user_func( $callback ); - if ( false === $return ) { + if ( is_string( $return ) ) { + $message = $return; + } elseif ( false === $return ) { $callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback; $ran = false; $message = sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string ); From 82c2a2dd868abdf80c8930c0fe77e73724616ee0 Mon Sep 17 00:00:00 2001 From: Anton Timmermans Date: Mon, 24 Apr 2017 13:22:47 +0200 Subject: [PATCH 005/189] Change build_payload from private to public --- includes/class-wc-webhook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-webhook.php b/includes/class-wc-webhook.php index bb24408c850..112a592fc3b 100644 --- a/includes/class-wc-webhook.php +++ b/includes/class-wc-webhook.php @@ -335,7 +335,7 @@ class WC_Webhook { * @param mixed $resource_id first hook argument, typically the resource ID * @return mixed payload data */ - private function build_payload( $resource_id ) { + public function build_payload( $resource_id ) { // build the payload with the same user context as the user who created // the webhook -- this avoids permission errors as background processing // runs with no user context From 7dc1300811ea6c8a06bf20386a56d76ce99d85d4 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 24 Apr 2017 18:11:16 +0100 Subject: [PATCH 006/189] change price queries --- includes/class-wc-query.php | 38 ++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/includes/class-wc-query.php b/includes/class-wc-query.php index 66127445711..eee7ccbc2d7 100644 --- a/includes/class-wc-query.php +++ b/includes/class-wc-query.php @@ -413,6 +413,8 @@ class WC_Query { * Remove ordering queries. */ public function remove_ordering_args() { + remove_filter( 'posts_clauses', array( $this, 'order_by_price_asc_post_clauses' ) ); + remove_filter( 'posts_clauses', array( $this, 'order_by_price_desc_post_clauses' ) ); remove_filter( 'posts_clauses', array( $this, 'order_by_popularity_post_clauses' ) ); remove_filter( 'posts_clauses', array( $this, 'order_by_rating_post_clauses' ) ); } @@ -459,9 +461,11 @@ class WC_Query { $args['order'] = ( 'ASC' === $order ) ? 'ASC' : 'DESC'; break; case 'price' : - $args['orderby'] = "meta_value_num ID"; - $args['order'] = ( 'DESC' === $order ) ? 'DESC' : 'ASC'; - $args['meta_key'] = '_price'; + if ( 'DESC' === $order ) { + add_filter( 'posts_clauses', array( $this, 'order_by_price_desc_post_clauses' ) ); + } else { + add_filter( 'posts_clauses', array( $this, 'order_by_price_asc_post_clauses' ) ); + } break; case 'popularity' : $args['meta_key'] = 'total_sales'; @@ -485,6 +489,34 @@ class WC_Query { return apply_filters( 'woocommerce_get_catalog_ordering_args', $args ); } + /** + * Handle numeric price sorting. + * + * @access public + * @param array $args + * @return array + */ + public function order_by_price_asc_post_clauses( $args ) { + global $wpdb; + $args['join'] = " INNER JOIN ( SELECT post_id, min( meta_value+0 ) price FROM $wpdb->postmeta WHERE meta_key='_price' GROUP BY post_id ) as price_query ON $wpdb->posts.ID = price_query.post_id "; + $args['orderby'] = " price_query.price ASC "; + return $args; + } + + /** + * Handle numeric price sorting. + * + * @access public + * @param array $args + * @return array + */ + public function order_by_price_desc_post_clauses( $args ) { + global $wpdb; + $args['join'] = " INNER JOIN ( SELECT post_id, max( meta_value+0 ) price FROM $wpdb->postmeta WHERE meta_key='_price' GROUP BY post_id ) as price_query ON $wpdb->posts.ID = price_query.post_id "; + $args['orderby'] = " price_query.price DESC "; + return $args; + } + /** * WP Core doens't let us change the sort direction for invidual orderby params - https://core.trac.wordpress.org/ticket/17065. * From 29fa59a0b7860b3918d9b5183899cec8ef5a9048 Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Mon, 24 Apr 2017 11:33:17 -0700 Subject: [PATCH 007/189] WC_Object_Query --- .../abstracts/abstract-wc-object-query.php | 107 ++++++++++++++++++ tests/bootstrap.php | 1 + .../class-wc-mock-wc-object-query.php | 6 + tests/unit-tests/crud/query.php | 31 +++++ woocommerce.php | 1 + 5 files changed, 146 insertions(+) create mode 100644 includes/abstracts/abstract-wc-object-query.php create mode 100644 tests/framework/class-wc-mock-wc-object-query.php create mode 100644 tests/unit-tests/crud/query.php diff --git a/includes/abstracts/abstract-wc-object-query.php b/includes/abstracts/abstract-wc-object-query.php new file mode 100644 index 00000000000..dd2f1a5f87a --- /dev/null +++ b/includes/abstracts/abstract-wc-object-query.php @@ -0,0 +1,107 @@ +query_vars = wp_parse_args( $args, $this->get_default_query_vars() ); + } + + /** + * Get the value of a query variable. + * @param string $query_var Query variable to get value for. + * @param mixed $default Default value if query variable is not set. + * @return mixed Query variable value if set, otherwise default. + */ + public function get( $query_var, $default = '' ) { + if ( isset( $this->query_vars[ $query_var ] ) ) { + return $this->query_vars[ $query_var ]; + } + return $default; + } + + /** + * Set a query variable. + * @param string $query_var Query variable to set. + * @param mixed $value Value to set for query variable. + */ + public function set( $query_var, $value ) { + $this->query_vars[$query_var] = $value; + } + + /** + * Get the default, unset allowed query vars. + * @return array + */ + protected function get_default_query_vars() { + + return array( + 'tax_query' => array(), + 'meta_query' => array(), + 'date_query' => array(), + + 'p' => '', + 'name' => '', + 'post_parent' => '', + 'post_parent__in' => array(), + 'post_parent__not_in' => array(), + 'post__in' => array(), + 'post__not_in' => array(), + + 'has_password' => null, + 'post_password' => '', + + 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit' ), + + 'posts_per_page' => 10, + 'nopaging' => false, + 'page' => 1, + 'offset' => 0, + + 'order' => 'DESC', + 'orderby' => 'date', + + 'year' => '', + 'monthnum' => '', + 'w' => '', + 'day' => '', + 'hour' => '', + 'minute' => '', + 'second' => '', + 'm' => '', + + 'meta_key' => '', + 'meta_value' => '', + 'meta_value_num' => '', + 'meta_compare' => '=', + + 's' => '', + 'exact' => true, + 'sentence' => '', + + 'fields' => '', + ); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 78156064c22..7973a117ed6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -102,6 +102,7 @@ class WC_Unit_Tests_Bootstrap { require_once( $this->tests_dir . '/framework/class-wc-unit-test-factory.php' ); require_once( $this->tests_dir . '/framework/class-wc-mock-session-handler.php' ); require_once( $this->tests_dir . '/framework/class-wc-mock-wc-data.php' ); + require_once( $this->tests_dir . '/framework/class-wc-mock-wc-object-query.php' ); require_once( $this->tests_dir . '/framework/class-wc-payment-token-stub.php' ); require_once( $this->tests_dir . '/framework/vendor/class-wp-test-spy-rest-server.php' ); diff --git a/tests/framework/class-wc-mock-wc-object-query.php b/tests/framework/class-wc-mock-wc-object-query.php new file mode 100644 index 00000000000..de19aac0941 --- /dev/null +++ b/tests/framework/class-wc-mock-wc-object-query.php @@ -0,0 +1,6 @@ +assertNotEmpty( $query->query_vars ); + $this->assertEquals( '', $query->get( 'post_parent' ) ); + $this->assertEquals( 'date', $query->get( 'orderby' ) ); + } + + function test_query_with_args() { + $args = array( + 'posts_per_page' => 15, + 'year' => 2017 + ); + $query = new WC_Mock_WC_Object_Query( $args ); + + $this->assertEquals( 15, $query->get( 'posts_per_page' ) ); + $this->assertEquals( 2017, $query->get( 'year' ) ); + + $query->set( 'year', 2016 ); + $this->assertEquals( 2016, $query->get( 'year' ) ); + } + +} diff --git a/woocommerce.php b/woocommerce.php index f74c55a931a..6143e0d633d 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -280,6 +280,7 @@ final class WooCommerce { * Abstract classes. */ include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-data.php' ); // WC_Data for CRUD + include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-object-query.php' ); // WC_Object_Query for CRUD include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-token.php' ); // Payment Tokens include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-product.php' ); // Products include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-order.php' ); // Orders From 553a12203bcb78ef6b486b2b27e2161e4507e5dd Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Mon, 24 Apr 2017 16:28:13 -0700 Subject: [PATCH 008/189] WC_Order_Query --- .../abstracts/abstract-wc-object-query.php | 70 +++++++++--------- includes/class-wc-order-query.php | 74 +++++++++++++++++++ tests/unit-tests/crud/query.php | 7 +- tests/unit-tests/order/query.php | 15 ++++ woocommerce.php | 1 + 5 files changed, 128 insertions(+), 39 deletions(-) create mode 100644 includes/class-wc-order-query.php create mode 100644 tests/unit-tests/order/query.php diff --git a/includes/abstracts/abstract-wc-object-query.php b/includes/abstracts/abstract-wc-object-query.php index dd2f1a5f87a..e1e60ba26c1 100644 --- a/includes/abstracts/abstract-wc-object-query.php +++ b/includes/abstracts/abstract-wc-object-query.php @@ -58,50 +58,50 @@ abstract class WC_Object_Query { protected function get_default_query_vars() { return array( - 'tax_query' => array(), - 'meta_query' => array(), - 'date_query' => array(), + 'tax_query' => array(), + 'meta_query' => array(), + 'date_query' => array(), - 'p' => '', - 'name' => '', - 'post_parent' => '', - 'post_parent__in' => array(), - 'post_parent__not_in' => array(), - 'post__in' => array(), - 'post__not_in' => array(), + 'p' => '', + 'name' => '', + 'parent' => '', + 'parent__in' => array(), + 'parent__not_in' => array(), + 'in' => array(), + 'not_in' => array(), - 'has_password' => null, - 'post_password' => '', + 'has_password' => null, + 'password' => '', - 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit' ), + 'status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit' ), - 'posts_per_page' => 10, - 'nopaging' => false, - 'page' => 1, - 'offset' => 0, + 'per_page' => 10, + 'nopaging' => false, + 'page' => 1, + 'offset' => 0, - 'order' => 'DESC', - 'orderby' => 'date', + 'order' => 'DESC', + 'orderby' => 'date', - 'year' => '', - 'monthnum' => '', - 'w' => '', - 'day' => '', - 'hour' => '', - 'minute' => '', - 'second' => '', - 'm' => '', + 'year' => '', + 'monthnum' => '', + 'w' => '', + 'day' => '', + 'hour' => '', + 'minute' => '', + 'second' => '', + 'm' => '', - 'meta_key' => '', - 'meta_value' => '', - 'meta_value_num' => '', - 'meta_compare' => '=', + 'meta_key' => '', + 'meta_value' => '', + 'meta_value_num' => '', + 'meta_compare' => '=', - 's' => '', - 'exact' => true, - 'sentence' => '', + 's' => '', + 'exact' => true, + 'sentence' => '', - 'fields' => '', + 'fields' => '', ); } } diff --git a/includes/class-wc-order-query.php b/includes/class-wc-order-query.php new file mode 100644 index 00000000000..6cec8ed4909 --- /dev/null +++ b/includes/class-wc-order-query.php @@ -0,0 +1,74 @@ + array_keys( wc_get_order_statuses() ), + 'type' => wc_get_order_types( 'view-orders' ), + 'currency' => '', + 'version' => '', + 'prices_include_tax' => '', + 'date_created' => '', + 'date_modified' => '', + 'discount_total' => '', + 'discount_tax' => '', + 'shipping_total' => '', + 'shipping_tax' => '', + 'cart_tax' => '', + 'total' => '', + 'total_tax' => '', + 'customer_id' => '', + 'order_key' => '', + 'billing_first_name' => '', + 'billing_last_name' => '', + 'billing_company' => '', + 'billing_address_1' => '', + 'billing_address_2' => '', + 'billing_city' => '', + 'billing_state' => '', + 'billing_postcode' => '', + 'billing_country' => '', + 'billing_email' => '', + 'billing_phone' => '', + 'shipping_first_name' => '', + 'shipping_last_name' => '', + 'shipping_company' => '', + 'shipping_address_1' => '', + 'shipping_address_2' => '', + 'shipping_city' => '', + 'shipping_state' => '', + 'shipping_postcode' => '', + 'shipping_country' => '', + 'payment_method' => '', + 'payment_method_title' => '', + 'transaction_id' => '', + 'customer_ip_address' => '', + 'customer_user_agent' => '', + 'created_via' => '', + 'customer_note' => '', + 'date_completed' => '', + 'date_paid' => '', + ) + ); + + } + + public function get_orders() { + return WC_Data_Store::load( 'order' )->query_orders( $this->query_vars ); + } + +} diff --git a/tests/unit-tests/crud/query.php b/tests/unit-tests/crud/query.php index b96298dbb3e..adaef271d7e 100644 --- a/tests/unit-tests/crud/query.php +++ b/tests/unit-tests/crud/query.php @@ -10,22 +10,21 @@ class WC_Tests_WC_Object_Query extends WC_Unit_Test_Case { $query = new WC_Mock_WC_Object_Query(); $this->assertNotEmpty( $query->query_vars ); - $this->assertEquals( '', $query->get( 'post_parent' ) ); + $this->assertEquals( '', $query->get( 'parent' ) ); $this->assertEquals( 'date', $query->get( 'orderby' ) ); } function test_query_with_args() { $args = array( - 'posts_per_page' => 15, + 'per_page' => 15, 'year' => 2017 ); $query = new WC_Mock_WC_Object_Query( $args ); - $this->assertEquals( 15, $query->get( 'posts_per_page' ) ); + $this->assertEquals( 15, $query->get( 'per_page' ) ); $this->assertEquals( 2017, $query->get( 'year' ) ); $query->set( 'year', 2016 ); $this->assertEquals( 2016, $query->get( 'year' ) ); } - } diff --git a/tests/unit-tests/order/query.php b/tests/unit-tests/order/query.php new file mode 100644 index 00000000000..15f528f96cc --- /dev/null +++ b/tests/unit-tests/order/query.php @@ -0,0 +1,15 @@ +assertEquals( '', $query->get( 'total' ) ); + $this->assertEquals( wc_get_order_types( 'view-orders' ), $query->get( 'type' ) ); + } + +} diff --git a/woocommerce.php b/woocommerce.php index 6143e0d633d..7dc7ad43aff 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -308,6 +308,7 @@ final class WooCommerce { include_once( WC_ABSPATH . 'includes/class-wc-data-exception.php' ); include_once( WC_ABSPATH . 'includes/class-wc-query.php' ); include_once( WC_ABSPATH . 'includes/class-wc-order-factory.php' ); // Order factory + include_once( WC_ABSPATH . 'includes/class-wc-order-query.php' ); // Order query include_once( WC_ABSPATH . 'includes/class-wc-product-factory.php' ); // Product factory include_once( WC_ABSPATH . 'includes/class-wc-payment-tokens.php' ); // Payment tokens controller include_once( WC_ABSPATH . 'includes/class-wc-shipping-zone.php' ); From b073454bfc2c2530d9b0bc534c81f2a5e2cb8daf Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 25 Apr 2017 12:11:28 +0100 Subject: [PATCH 009/189] Join needs to append --- includes/class-wc-query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-query.php b/includes/class-wc-query.php index eee7ccbc2d7..9fdd52ffbb9 100644 --- a/includes/class-wc-query.php +++ b/includes/class-wc-query.php @@ -498,7 +498,7 @@ class WC_Query { */ public function order_by_price_asc_post_clauses( $args ) { global $wpdb; - $args['join'] = " INNER JOIN ( SELECT post_id, min( meta_value+0 ) price FROM $wpdb->postmeta WHERE meta_key='_price' GROUP BY post_id ) as price_query ON $wpdb->posts.ID = price_query.post_id "; + $args['join'] .= " INNER JOIN ( SELECT post_id, min( meta_value+0 ) price FROM $wpdb->postmeta WHERE meta_key='_price' GROUP BY post_id ) as price_query ON $wpdb->posts.ID = price_query.post_id "; $args['orderby'] = " price_query.price ASC "; return $args; } @@ -512,7 +512,7 @@ class WC_Query { */ public function order_by_price_desc_post_clauses( $args ) { global $wpdb; - $args['join'] = " INNER JOIN ( SELECT post_id, max( meta_value+0 ) price FROM $wpdb->postmeta WHERE meta_key='_price' GROUP BY post_id ) as price_query ON $wpdb->posts.ID = price_query.post_id "; + $args['join'] .= " INNER JOIN ( SELECT post_id, max( meta_value+0 ) price FROM $wpdb->postmeta WHERE meta_key='_price' GROUP BY post_id ) as price_query ON $wpdb->posts.ID = price_query.post_id "; $args['orderby'] = " price_query.price DESC "; return $args; } From 2b3ec357adb73a935064ada83aae0bb533e0f4f7 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Tue, 25 Apr 2017 14:12:36 +0300 Subject: [PATCH 010/189] fix-14302 --- includes/abstracts/abstract-wc-order.php | 7 +++---- includes/class-wc-checkout.php | 2 +- includes/class-wc-order-factory.php | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index 39af9816eee..168768766c3 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -798,9 +798,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { * @return string */ protected function get_items_key( $item ) { - if ( is_a( $item, 'WC_Order_Item_Product' ) ) { - return 'line_items'; - } elseif ( is_a( $item, 'WC_Order_Item_Fee' ) ) { + + if ( is_a( $item, 'WC_Order_Item_Fee' ) ) { return 'fee_lines'; } elseif ( is_a( $item, 'WC_Order_Item_Shipping' ) ) { return 'shipping_lines'; @@ -809,7 +808,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { } elseif ( is_a( $item, 'WC_Order_Item_Coupon' ) ) { return 'coupon_lines'; } else { - return ''; + return 'line_items'; } } diff --git a/includes/class-wc-checkout.php b/includes/class-wc-checkout.php index 1fd7117c504..be2f4de8244 100644 --- a/includes/class-wc-checkout.php +++ b/includes/class-wc-checkout.php @@ -349,7 +349,7 @@ class WC_Checkout { public function create_order_line_items( &$order, $cart ) { foreach ( $cart->get_cart() as $cart_item_key => $values ) { $product = $values['data']; - $item = new WC_Order_Item_Product(); + $item = apply_filters( 'woocommerce_order_line_item', new WC_Order_Item_Product()); $item->legacy_values = $values; // @deprecated For legacy actions. $item->legacy_cart_item_key = $cart_item_key; // @deprecated For legacy actions. $item->set_props( array( diff --git a/includes/class-wc-order-factory.php b/includes/class-wc-order-factory.php index f465ee8e800..6cacce2c82f 100644 --- a/includes/class-wc-order-factory.php +++ b/includes/class-wc-order-factory.php @@ -79,6 +79,7 @@ class WC_Order_Factory { case 'line_item' : case 'product' : $classname = 'WC_Order_Item_Product'; + $classname = apply_filters( 'woocommerce_get_order_item_classname', $classname, $item_type, $id ); break; case 'coupon' : $classname = 'WC_Order_Item_Coupon'; From f71a4988923c75dc64d0629857a482b6bbc79d64 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Tue, 25 Apr 2017 16:06:43 +0300 Subject: [PATCH 011/189] Allows to insert conditions for our custom "woocommerce_order_line_item" filter. --- 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 41551c3ab6a..4e2c9716525 100644 --- a/includes/class-wc-checkout.php +++ b/includes/class-wc-checkout.php @@ -349,7 +349,7 @@ class WC_Checkout { public function create_order_line_items( &$order, $cart ) { foreach ( $cart->get_cart() as $cart_item_key => $values ) { $product = $values['data']; - $item = apply_filters( 'woocommerce_order_line_item', new WC_Order_Item_Product()); + $item = apply_filters( 'woocommerce_order_line_item', new WC_Order_Item_Product(), $product); $item->legacy_values = $values; // @deprecated For legacy actions. $item->legacy_cart_item_key = $cart_item_key; // @deprecated For legacy actions. $item->set_props( array( From 1e6d52a3bd6e9e1b618d8deaa0cb25c1f414a363 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 25 Apr 2017 14:31:24 +0100 Subject: [PATCH 012/189] Add a data-caption for captions and keep title around. Fixes #14578 --- assets/js/frontend/single-product.js | 8 ++++---- assets/js/frontend/single-product.min.js | 2 +- templates/single-product/product-image.php | 6 +++--- templates/single-product/product-thumbnails.php | 9 ++++----- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/assets/js/frontend/single-product.js b/assets/js/frontend/single-product.js index 56dca70979d..823092feb7b 100644 --- a/assets/js/frontend/single-product.js +++ b/assets/js/frontend/single-product.js @@ -227,10 +227,10 @@ jQuery( function( $ ) { large_image_w = img.attr( 'data-large_image_width' ), large_image_h = img.attr( 'data-large_image_height' ), item = { - src: large_image_src, - w: large_image_w, - h: large_image_h, - title: img.attr( 'title' ) + src : large_image_src, + w : large_image_w, + h : large_image_h, + title: img.attr( 'data-caption' ) ? img.attr( 'data-caption' ) : img.attr( 'title' ) }; items.push( item ); } ); diff --git a/assets/js/frontend/single-product.min.js b/assets/js/frontend/single-product.min.js index b7a7cb4e721..dbf096e6ac9 100644 --- a/assets/js/frontend/single-product.min.js +++ b/assets/js/frontend/single-product.min.js @@ -1 +1 @@ -jQuery(function(a){if("undefined"==typeof wc_single_product_params)return!1;a("body").on("init",".wc-tabs-wrapper, .woocommerce-tabs",function(){a(".wc-tab, .woocommerce-tabs .panel:not(.panel .panel)").hide();var b=window.location.hash,c=window.location.href,d=a(this).find(".wc-tabs, ul.tabs").first();b.toLowerCase().indexOf("comment-")>=0||"#reviews"===b||"#tab-reviews"===b?d.find("li.reviews_tab a").click():c.indexOf("comment-page-")>0||c.indexOf("cpage=")>0?d.find("li.reviews_tab a").click():d.find("li:first a").click()}).on("click",".wc-tabs li a, ul.tabs li a",function(b){b.preventDefault();var c=a(this),d=c.closest(".wc-tabs-wrapper, .woocommerce-tabs"),e=d.find(".wc-tabs, ul.tabs");e.find("li").removeClass("active"),d.find(".wc-tab, .panel:not(.panel .panel)").hide(),c.closest("li").addClass("active"),d.find(c.attr("href")).show()}).on("click","a.woocommerce-review-link",function(){return a(".reviews_tab a").click(),!0}).on("init","#rating",function(){a("#rating").hide().before('

12345

')}).on("click","#respond p.stars a",function(){var b=a(this),c=a(this).closest("#respond").find("#rating"),d=a(this).closest(".stars");return c.val(b.text()),b.siblings("a").removeClass("active"),b.addClass("active"),d.addClass("selected"),!1}).on("click","#respond #submit",function(){var b=a(this).closest("#respond").find("#rating"),c=b.val();if(b.length>0&&!c&&"yes"===wc_single_product_params.review_rating_required)return window.alert(wc_single_product_params.i18n_required_rating_text),!1}),a(".wc-tabs-wrapper, .woocommerce-tabs, #rating").trigger("init");var b=function(b,c){return this.$target=b,this.$images=a(".woocommerce-product-gallery__image",b),0===this.$images.length?void this.$target.css("opacity",1):(b.data("product_gallery",this),this.flexslider_enabled=a.isFunction(a.fn.flexslider)&&wc_single_product_params.flexslider_enabled,this.zoom_enabled=a.isFunction(a.fn.zoom)&&wc_single_product_params.zoom_enabled,this.photoswipe_enabled="undefined"!=typeof PhotoSwipe&&wc_single_product_params.photoswipe_enabled,c&&(this.flexslider_enabled=!1!==c.photoswipe_enabled&&this.flexslider_enabled,this.zoom_enabled=!1!==c.zoom_enabled&&this.zoom_enabled,this.photoswipe_enabled=!1!==c.photoswipe_enabled&&this.photoswipe_enabled),this.initFlexslider=this.initFlexslider.bind(this),this.initZoom=this.initZoom.bind(this),this.initPhotoswipe=this.initPhotoswipe.bind(this),this.onResetSlidePosition=this.onResetSlidePosition.bind(this),this.getGalleryItems=this.getGalleryItems.bind(this),this.openPhotoswipe=this.openPhotoswipe.bind(this),this.flexslider_enabled?(this.initFlexslider(),b.on("woocommerce_gallery_reset_slide_position",this.onResetSlidePosition)):this.$target.css("opacity",1),this.zoom_enabled&&(this.initZoom(),b.on("woocommerce_gallery_init_zoom",this.initZoom)),void(this.photoswipe_enabled&&this.initPhotoswipe()))};b.prototype.initFlexslider=function(){var b=this.$images,c=this.$target;c.flexslider({selector:".woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image",animation:wc_single_product_params.flexslider.animation,smoothHeight:wc_single_product_params.flexslider.smoothHeight,directionNav:wc_single_product_params.flexslider.directionNav,controlNav:wc_single_product_params.flexslider.controlNav,slideshow:wc_single_product_params.flexslider.slideshow,animationSpeed:wc_single_product_params.flexslider.animationSpeed,animationLoop:wc_single_product_params.flexslider.animationLoop,start:function(){c.css("opacity",1);var d=0;b.each(function(){var b=a(this).height();b>d&&(d=b)}),b.each(function(){a(this).css("min-height",d)})}})},b.prototype.initZoom=function(){var b=this.$images,c=this.$target.width(),d=!1;if(this.flexslider_enabled||(b=b.first()),a(b).each(function(b,e){var f=a(e).find("img");if(f.data("large_image_width")>c)return d=!0,!1}),d){var e={touch:!1};"ontouchstart"in window&&(e.on="click"),b.trigger("zoom.destroy"),b.zoom(e)}},b.prototype.initPhotoswipe=function(){this.zoom_enabled&&this.$images.length>0&&(this.$target.prepend('🔍'),this.$target.on("click",".woocommerce-product-gallery__trigger",this.openPhotoswipe)),this.$target.on("click",".woocommerce-product-gallery__image a",this.openPhotoswipe)},b.prototype.onResetSlidePosition=function(){this.$target.flexslider(0)},b.prototype.getGalleryItems=function(){var b=this.$images,c=[];return b.length>0&&b.each(function(b,d){var e=a(d).find("img"),f=e.attr("data-large_image"),g=e.attr("data-large_image_width"),h=e.attr("data-large_image_height"),i={src:f,w:g,h:h,title:e.attr("title")};c.push(i)}),c},b.prototype.openPhotoswipe=function(b){b.preventDefault();var c,d=a(".pswp")[0],e=this.getGalleryItems(),f=a(b.target);c=f.is(".woocommerce-product-gallery__trigger")?this.$target.find(".flex-active-slide"):f.closest(".woocommerce-product-gallery__image");var g={index:a(c).index(),shareEl:!1,closeOnScroll:!1,history:!1,hideAnimationDuration:0,showAnimationDuration:0},h=new PhotoSwipe(d,PhotoSwipeUI_Default,e,g);h.init()},a.fn.wc_product_gallery=function(a){return new b(this,a),this},a(".woocommerce-product-gallery").each(function(){a(this).wc_product_gallery()})}); \ No newline at end of file +jQuery(function(a){if("undefined"==typeof wc_single_product_params)return!1;a("body").on("init",".wc-tabs-wrapper, .woocommerce-tabs",function(){a(".wc-tab, .woocommerce-tabs .panel:not(.panel .panel)").hide();var b=window.location.hash,c=window.location.href,d=a(this).find(".wc-tabs, ul.tabs").first();b.toLowerCase().indexOf("comment-")>=0||"#reviews"===b||"#tab-reviews"===b?d.find("li.reviews_tab a").click():c.indexOf("comment-page-")>0||c.indexOf("cpage=")>0?d.find("li.reviews_tab a").click():d.find("li:first a").click()}).on("click",".wc-tabs li a, ul.tabs li a",function(b){b.preventDefault();var c=a(this),d=c.closest(".wc-tabs-wrapper, .woocommerce-tabs"),e=d.find(".wc-tabs, ul.tabs");e.find("li").removeClass("active"),d.find(".wc-tab, .panel:not(.panel .panel)").hide(),c.closest("li").addClass("active"),d.find(c.attr("href")).show()}).on("click","a.woocommerce-review-link",function(){return a(".reviews_tab a").click(),!0}).on("init","#rating",function(){a("#rating").hide().before('

12345

')}).on("click","#respond p.stars a",function(){var b=a(this),c=a(this).closest("#respond").find("#rating"),d=a(this).closest(".stars");return c.val(b.text()),b.siblings("a").removeClass("active"),b.addClass("active"),d.addClass("selected"),!1}).on("click","#respond #submit",function(){var b=a(this).closest("#respond").find("#rating"),c=b.val();if(b.length>0&&!c&&"yes"===wc_single_product_params.review_rating_required)return window.alert(wc_single_product_params.i18n_required_rating_text),!1}),a(".wc-tabs-wrapper, .woocommerce-tabs, #rating").trigger("init");var b=function(b,c){return this.$target=b,this.$images=a(".woocommerce-product-gallery__image",b),0===this.$images.length?void this.$target.css("opacity",1):(b.data("product_gallery",this),this.flexslider_enabled=a.isFunction(a.fn.flexslider)&&wc_single_product_params.flexslider_enabled,this.zoom_enabled=a.isFunction(a.fn.zoom)&&wc_single_product_params.zoom_enabled,this.photoswipe_enabled="undefined"!=typeof PhotoSwipe&&wc_single_product_params.photoswipe_enabled,c&&(this.flexslider_enabled=!1!==c.flexslider_enabled&&this.flexslider_enabled,this.zoom_enabled=!1!==c.zoom_enabled&&this.zoom_enabled,this.photoswipe_enabled=!1!==c.photoswipe_enabled&&this.photoswipe_enabled),this.initFlexslider=this.initFlexslider.bind(this),this.initZoom=this.initZoom.bind(this),this.initPhotoswipe=this.initPhotoswipe.bind(this),this.onResetSlidePosition=this.onResetSlidePosition.bind(this),this.getGalleryItems=this.getGalleryItems.bind(this),this.openPhotoswipe=this.openPhotoswipe.bind(this),this.flexslider_enabled?(this.initFlexslider(),b.on("woocommerce_gallery_reset_slide_position",this.onResetSlidePosition)):this.$target.css("opacity",1),this.zoom_enabled&&(this.initZoom(),b.on("woocommerce_gallery_init_zoom",this.initZoom)),void(this.photoswipe_enabled&&this.initPhotoswipe()))};b.prototype.initFlexslider=function(){var b=this.$images,c=this.$target;c.flexslider({selector:".woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image",animation:wc_single_product_params.flexslider.animation,smoothHeight:wc_single_product_params.flexslider.smoothHeight,directionNav:wc_single_product_params.flexslider.directionNav,controlNav:wc_single_product_params.flexslider.controlNav,slideshow:wc_single_product_params.flexslider.slideshow,animationSpeed:wc_single_product_params.flexslider.animationSpeed,animationLoop:wc_single_product_params.flexslider.animationLoop,start:function(){c.css("opacity",1);var d=0;b.each(function(){var b=a(this).height();b>d&&(d=b)}),b.each(function(){a(this).css("min-height",d)})}})},b.prototype.initZoom=function(){var b=this.$images,c=this.$target.width(),d=!1;if(this.flexslider_enabled||(b=b.first()),a(b).each(function(b,e){var f=a(e).find("img");if(f.data("large_image_width")>c)return d=!0,!1}),d){var e={touch:!1};"ontouchstart"in window&&(e.on="click"),b.trigger("zoom.destroy"),b.zoom(e)}},b.prototype.initPhotoswipe=function(){this.zoom_enabled&&this.$images.length>0&&(this.$target.prepend('🔍'),this.$target.on("click",".woocommerce-product-gallery__trigger",this.openPhotoswipe)),this.$target.on("click",".woocommerce-product-gallery__image a",this.openPhotoswipe)},b.prototype.onResetSlidePosition=function(){this.$target.flexslider(0)},b.prototype.getGalleryItems=function(){var b=this.$images,c=[];return b.length>0&&b.each(function(b,d){var e=a(d).find("img"),f=e.attr("data-large_image"),g=e.attr("data-large_image_width"),h=e.attr("data-large_image_height"),i={src:f,w:g,h:h,title:e.attr("data-caption")?e.attr("data-caption"):e.attr("title")};c.push(i)}),c},b.prototype.openPhotoswipe=function(b){b.preventDefault();var c,d=a(".pswp")[0],e=this.getGalleryItems(),f=a(b.target);c=f.is(".woocommerce-product-gallery__trigger")?this.$target.find(".flex-active-slide"):f.closest(".woocommerce-product-gallery__image");var g={index:a(c).index(),shareEl:!1,closeOnScroll:!1,history:!1,hideAnimationDuration:0,showAnimationDuration:0},h=new PhotoSwipe(d,PhotoSwipeUI_Default,e,g);h.init()},a.fn.wc_product_gallery=function(a){return new b(this,a),this},a(".woocommerce-product-gallery").each(function(){a(this).wc_product_gallery()})}); \ No newline at end of file diff --git a/templates/single-product/product-image.php b/templates/single-product/product-image.php index 1fe188f78ac..ce694db9bf0 100644 --- a/templates/single-product/product-image.php +++ b/templates/single-product/product-image.php @@ -13,7 +13,7 @@ * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates - * @version 3.0.2 + * @version 3.1.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -25,7 +25,6 @@ $columns = apply_filters( 'woocommerce_product_thumbnails_columns', 4 $thumbnail_size = apply_filters( 'woocommerce_product_thumbnails_large_size', 'full' ); $post_thumbnail_id = get_post_thumbnail_id( $post->ID ); $full_size_image = wp_get_attachment_image_src( $post_thumbnail_id, $thumbnail_size ); -$image_title = get_post_field( 'post_excerpt', $post_thumbnail_id ); $placeholder = has_post_thumbnail() ? 'with-images' : 'without-images'; $wrapper_classes = apply_filters( 'woocommerce_single_product_image_gallery_classes', array( 'woocommerce-product-gallery', @@ -38,7 +37,8 @@ $wrapper_classes = apply_filters( 'woocommerce_single_product_image_gallery_cl