From 0f8fa8f10f4724bcb3c59043c8ce52bf0dea9615 Mon Sep 17 00:00:00 2001 From: terence1990 Date: Sun, 16 Oct 2016 15:24:55 +0100 Subject: [PATCH 01/15] New Action for after Product Attribute Settings Allows developers to add extra checkboxes etc. --- includes/admin/meta-boxes/views/html-product-attribute.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/admin/meta-boxes/views/html-product-attribute.php b/includes/admin/meta-boxes/views/html-product-attribute.php index 7328257f6fa..4eab03e690a 100644 --- a/includes/admin/meta-boxes/views/html-product-attribute.php +++ b/includes/admin/meta-boxes/views/html-product-attribute.php @@ -77,6 +77,7 @@ + From a86d4f62f38c765b13967811e59d847323c61013 Mon Sep 17 00:00:00 2001 From: terenceneedssurgery Date: Thu, 23 Mar 2017 11:25:08 +0000 Subject: [PATCH 02/15] Checkout: Order Pay to Template --- .../class-wc-shortcode-checkout.php | 33 ++---------- templates/checkout/order-pay.php | 50 +++++++++++++++++++ 2 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 templates/checkout/order-pay.php diff --git a/includes/shortcodes/class-wc-shortcode-checkout.php b/includes/shortcodes/class-wc-shortcode-checkout.php index d9559f18785..4af81b16e04 100644 --- a/includes/shortcodes/class-wc-shortcode-checkout.php +++ b/includes/shortcodes/class-wc-shortcode-checkout.php @@ -130,35 +130,10 @@ class WC_Shortcode_Checkout { if ( $order->needs_payment() ) { - ?> - - - get_payment_method(), $order_id ); ?> - -
- $order + ) ); + } else { wc_add_notice( sprintf( __( 'This order’s status is “%s”—it cannot be paid for. Please contact us if you need assistance.', 'woocommerce' ), wc_get_order_status_name( $order->get_status() ) ), 'error' ); } diff --git a/templates/checkout/order-pay.php b/templates/checkout/order-pay.php new file mode 100644 index 00000000000..c48f67a48e7 --- /dev/null +++ b/templates/checkout/order-pay.php @@ -0,0 +1,50 @@ + + + + +payment_method, $order_id ); ?> + +
\ No newline at end of file From c5a75a544252793ce9f9095b78734c9cde1f099f Mon Sep 17 00:00:00 2001 From: Terence O'Donoghue Date: Tue, 11 Jul 2017 09:51:11 +0100 Subject: [PATCH 03/15] Use ::get_payment_method_title --- templates/checkout/order-pay.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/checkout/order-pay.php b/templates/checkout/order-pay.php index c48f67a48e7..b53ee437222 100644 --- a/templates/checkout/order-pay.php +++ b/templates/checkout/order-pay.php @@ -35,11 +35,11 @@ if ( ! defined( 'ABSPATH' ) ) { get_formatted_order_total(); ?> - payment_method_title) : ?> + get_payment_method_title() ) : ?>
  • payment_method_title; + echo $order->get_payment_method_title(); ?>
  • From 43eaa8356af4ca3272101bbe5dc74f3c172e53c1 Mon Sep 17 00:00:00 2001 From: Terence O'Donoghue Date: Tue, 11 Jul 2017 09:53:50 +0100 Subject: [PATCH 04/15] Fixed template reference spacing --- includes/shortcodes/class-wc-shortcode-checkout.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/shortcodes/class-wc-shortcode-checkout.php b/includes/shortcodes/class-wc-shortcode-checkout.php index 4af81b16e04..1308b7e4df3 100644 --- a/includes/shortcodes/class-wc-shortcode-checkout.php +++ b/includes/shortcodes/class-wc-shortcode-checkout.php @@ -130,9 +130,7 @@ class WC_Shortcode_Checkout { if ( $order->needs_payment() ) { - wc_get_template( 'checkout/order-pay.php', array( - 'order' => $order - ) ); + wc_get_template( 'checkout/order-pay.php', array( 'order' => $order ) ); } else { wc_add_notice( sprintf( __( 'This order’s status is “%s”—it cannot be paid for. Please contact us if you need assistance.', 'woocommerce' ), wc_get_order_status_name( $order->get_status() ) ), 'error' ); From 8f6dc9588ca6611073b515763cdbfea42b886e3d Mon Sep 17 00:00:00 2001 From: Terence O'Donoghue Date: Tue, 11 Jul 2017 09:57:56 +0100 Subject: [PATCH 05/15] Fixed reference to deprecated WC_Order properties --- templates/checkout/order-pay.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/checkout/order-pay.php b/templates/checkout/order-pay.php index b53ee437222..f6dc857248a 100644 --- a/templates/checkout/order-pay.php +++ b/templates/checkout/order-pay.php @@ -24,12 +24,12 @@ if ( ! defined( 'ABSPATH' ) ) {
    • - + get_order_number(); ?>
    • - order_date)); ?> + get_date_created() ); ?>
    • @@ -37,14 +37,14 @@ if ( ! defined( 'ABSPATH' ) ) {
    • get_payment_method_title() ) : ?>
    • - + get_payment_method_title(); + echo wp_kses_post( $order->get_payment_method_title() ); ?>
    -payment_method, $order_id ); ?> +get_payment_method(), $order_id ); ?>
    \ No newline at end of file From f93413920bc5a8db71451a9af341b9a680dc81ff Mon Sep 17 00:00:00 2001 From: terence1990 Date: Sat, 15 Jul 2017 17:41:34 +0100 Subject: [PATCH 06/15] Changed template name to receipt --- includes/shortcodes/class-wc-shortcode-checkout.php | 2 +- templates/checkout/{order-pay.php => order-receipt.php} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename templates/checkout/{order-pay.php => order-receipt.php} (93%) diff --git a/includes/shortcodes/class-wc-shortcode-checkout.php b/includes/shortcodes/class-wc-shortcode-checkout.php index 1308b7e4df3..33e4f63a363 100644 --- a/includes/shortcodes/class-wc-shortcode-checkout.php +++ b/includes/shortcodes/class-wc-shortcode-checkout.php @@ -130,7 +130,7 @@ class WC_Shortcode_Checkout { if ( $order->needs_payment() ) { - wc_get_template( 'checkout/order-pay.php', array( 'order' => $order ) ); + wc_get_template( 'checkout/order-receipt.php', array( 'order' => $order ) ); } else { wc_add_notice( sprintf( __( 'This order’s status is “%s”—it cannot be paid for. Please contact us if you need assistance.', 'woocommerce' ), wc_get_order_status_name( $order->get_status() ) ), 'error' ); diff --git a/templates/checkout/order-pay.php b/templates/checkout/order-receipt.php similarity index 93% rename from templates/checkout/order-pay.php rename to templates/checkout/order-receipt.php index f6dc857248a..ad50dff7e0d 100644 --- a/templates/checkout/order-pay.php +++ b/templates/checkout/order-receipt.php @@ -1,8 +1,8 @@ Date: Tue, 8 Aug 2017 12:47:16 +0200 Subject: [PATCH 07/15] Store status_transition in a local variable and reset it before firing hooks --- includes/class-wc-order.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php index d4db07492fd..0d665a6517e 100644 --- a/includes/class-wc-order.php +++ b/includes/class-wc-order.php @@ -303,25 +303,27 @@ class WC_Order extends WC_Abstract_Order { * Handle the status transition. */ protected function status_transition() { - if ( $this->status_transition ) { - do_action( 'woocommerce_order_status_' . $this->status_transition['to'], $this->get_id(), $this ); + $status_transition = $this->status_transition; - if ( ! empty( $this->status_transition['from'] ) ) { + // Reset status transition variable + $this->status_transition = false; + + if ( $status_transition ) { + do_action( 'woocommerce_order_status_' . $status_transition['to'], $this->get_id(), $this ); + + if ( ! empty( $status_transition['from'] ) ) { /* translators: 1: old order status 2: new order status */ - $transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $this->status_transition['from'] ), wc_get_order_status_name( $this->status_transition['to'] ) ); + $transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) ); - do_action( 'woocommerce_order_status_' . $this->status_transition['from'] . '_to_' . $this->status_transition['to'], $this->get_id(), $this ); - do_action( 'woocommerce_order_status_changed', $this->get_id(), $this->status_transition['from'], $this->status_transition['to'], $this ); + do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); + do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); } else { /* translators: %s: new order status */ - $transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $this->status_transition['to'] ) ); + $transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['to'] ) ); } // Note the transition occurred - $this->add_order_note( trim( $this->status_transition['note'] . ' ' . $transition_note ), 0, $this->status_transition['manual'] ); - - // This has ran, so reset status transition variable - $this->status_transition = false; + $this->add_order_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); } } From c1544e443aff848f570cfb01f8b5bd4cbcdf3ddb Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 9 Aug 2017 10:11:07 +0100 Subject: [PATCH 08/15] Version and escape --- templates/checkout/order-receipt.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/templates/checkout/order-receipt.php b/templates/checkout/order-receipt.php index ad50dff7e0d..21932a213f5 100644 --- a/templates/checkout/order-receipt.php +++ b/templates/checkout/order-receipt.php @@ -13,31 +13,30 @@ * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates - * @version 2.2.0 + * @version 3.2.0 */ if ( ! defined( 'ABSPATH' ) ) { - exit; // Exit if accessed directly + exit; } - ?>
    • - - get_order_number(); ?> + + get_order_number() ); ?>
    • - - get_date_created() ); ?> + + get_date_created() ) ); ?>
    • - - get_formatted_order_total(); ?> + + get_formatted_order_total() ); ?>
    • get_payment_method_title() ) : ?>
    • - + get_payment_method_title() ); ?> @@ -47,4 +46,4 @@ if ( ! defined( 'ABSPATH' ) ) { get_payment_method(), $order_id ); ?> -
      \ No newline at end of file +
      From 73350e5418a2f84b80db5746c8b03f75acac1d07 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 9 Aug 2017 11:59:50 +0100 Subject: [PATCH 09/15] Fake round half down in PHP 5,2 Fixes unit tests. --- includes/wc-cart-functions.php | 14 ++++++++++++- includes/wc-formatting-functions.php | 31 +++++++++++++++++++--------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index c9b44b75dd0..45fe70639da 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -369,7 +369,19 @@ function wc_cart_round_discount( $value, $precision ) { if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) { return round( $value, $precision, WC_DISCOUNT_ROUNDING_MODE ); } else { - return round( $value, $precision ); + // Fake it in PHP 5.2. + if ( 2 === WC_DISCOUNT_ROUNDING_MODE ) { + $value = (string) $value; + $value = explode( '.', $value ); + $value[1] = substr( $value[1], 0, $precision + 1 ); + $value = implode( '.', $value ); + + if ( substr( $value, -1 ) === '5' ) { + $value = substr( $value, 0, -1 ) . '4'; + } + $value = floatval( $value ); + } + return round( $value, $precision ); } } diff --git a/includes/wc-formatting-functions.php b/includes/wc-formatting-functions.php index c0d1ba2ff70..2e82cc325c8 100644 --- a/includes/wc-formatting-functions.php +++ b/includes/wc-formatting-functions.php @@ -216,21 +216,32 @@ function wc_trim_zeros( $price ) { /** * Round a tax amount. * - * @param double $tax Amount to round. - * @param int $dp DP to round. Defaults to wc_get_price_decimals. + * @param double $value Amount to round. + * @param int $precision DP to round. Defaults to wc_get_price_decimals. * @return double */ -function wc_round_tax_total( $tax, $dp = null ) { - $dp = is_null( $dp ) ? wc_get_price_decimals() : absint( $dp ); +function wc_round_tax_total( $value, $precision = null ) { + $precision = is_null( $precision ) ? wc_get_price_decimals() : absint( $precision ); - // @codeCoverageIgnoreStart - if ( version_compare( phpversion(), '5.3', '<' ) ) { - $rounded_tax = round( $tax, $dp ); + if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) { + $rounded_tax = round( $value, $precision, WC_TAX_ROUNDING_MODE ); } else { - // @codeCoverageIgnoreEnd - $rounded_tax = round( $tax, $dp, WC_TAX_ROUNDING_MODE ); + // Fake it in PHP 5.2. + if ( 2 === WC_TAX_ROUNDING_MODE ) { + $value = (string) $value; + $value = explode( '.', $value ); + $value[1] = substr( $value[1], 0, $precision + 1 ); + $value = implode( '.', $value ); + + if ( substr( $value, -1 ) === '5' ) { + $value = substr( $value, 0, -1 ) . '4'; + } + $value = floatval( $value ); + } + $rounded_tax = round( $value, $precision ); } - return apply_filters( 'wc_round_tax_total', $rounded_tax, $tax, $dp, WC_TAX_ROUNDING_MODE ); + + return apply_filters( 'wc_round_tax_total', $rounded_tax, $value, $precision, WC_TAX_ROUNDING_MODE ); } /** From 2ba0c643879ffb8884918eb3e3e32be301504b68 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 9 Aug 2017 17:13:00 +0100 Subject: [PATCH 10/15] readme --- readme.txt | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/readme.txt b/readme.txt index b5078d8cabd..817cc0efce9 100644 --- a/readme.txt +++ b/readme.txt @@ -162,6 +162,43 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woocommerce/wo == Changelog == = 3.2.0 - 2017-XX-XX = +* Feature - Simplified the ability to resend order details to customers with a single "Resend Order Details" action. +* Feature - Added store street address, city and postal code to settings for use by plugins. +* Feature - wrapping values in quotes now let's you use commas in the product CSV importer. +* Feature - If a fatal error occurs, WooCommerce will catch and log it to be viewed in WC > Status > Logs. +* Feature - Drag and drop sorting on the grouped product field to control display order. +* Feature - Integrated selectWoo; more accessible Select2 (enhanced select boxes) in admin and on the frontend. +* Feature - Enhanced select boxes in the shipping calculator. +* Feature - Enhanced select boxes in layered nav "or" widget. +* Feature - Ajaxified the product category filter on the products screen. +* Tweak - Made the buyer phone number clickable in the in the order backend. +* Tweak - Clean up user is_paying_customer after deleting an order. +* Tweak - If stock changes between page load and editing, reject stock changes to avoid incorrect stock changes. +* Tweak - Disable search engines indexing core, dynamic, cart/checkout pages. +* Tweak - Added shortcodes to description output in structured data, and improved variable product data. +* Tweak - Use ajax when restoring an item in the cart, and removing an item from the mini-cart. +* Tweak - Onboarding: added "next" button to pointers and allowed them to be dismissed. +* Tweak - Display post states for WC pages e.g. shop, checkout etc. +* Tweak - Improved order tracking page display and validation. +* Dev - Product CRUD search helpers. +* Dev - Refactor shipping rate to include instance IDs. +* Dev - New attribute helper functions. +* Dev - Order note helper functions. +* Dev - Added the "Terms and conditions" page to the api system status report. +* Dev - Made date inputs reusable. +* Dev - Added option for merging when using 'Order Again' via filter woocommerce_empty_cart_when_order_again. +* Dev - Added tool for repopulating order address search indexes. +* Dev - Added woocommerce_get_asset_url filter. +* Dev - Show notice when internal meta props are accessed directly. +* Dev - Improve meta data updates so data is only updated when changed. +* Dev - Improved get_filtered_term_product_counts performance. +* Dev - Introduced wc_get_account_orders_actions function. +* Theming - Display downloads in their own table, universally, using a new template file. +* Theming - Checkout: Order pay template +* Localization - Added cantons of Switzerland. +* Localization - Add rtl support for activation.css. +* Localization - Updated Mexican states to use correct 2 letter codes. +* Many smaller fixes and improvements - see Github! [See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce/master/CHANGELOG.txt). From aa82a54f477e9b3925acd8bf39f4d903b7c04956 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 9 Aug 2017 19:27:19 +0100 Subject: [PATCH 11/15] Prevent notices --- includes/wc-cart-functions.php | 2 +- includes/wc-formatting-functions.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index 45fe70639da..90dde98081a 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -370,7 +370,7 @@ function wc_cart_round_discount( $value, $precision ) { return round( $value, $precision, WC_DISCOUNT_ROUNDING_MODE ); } else { // Fake it in PHP 5.2. - if ( 2 === WC_DISCOUNT_ROUNDING_MODE ) { + if ( 2 === WC_DISCOUNT_ROUNDING_MODE && strstr( $value, '.' ) ) { $value = (string) $value; $value = explode( '.', $value ); $value[1] = substr( $value[1], 0, $precision + 1 ); diff --git a/includes/wc-formatting-functions.php b/includes/wc-formatting-functions.php index 2e82cc325c8..f49199bcde6 100644 --- a/includes/wc-formatting-functions.php +++ b/includes/wc-formatting-functions.php @@ -227,7 +227,7 @@ function wc_round_tax_total( $value, $precision = null ) { $rounded_tax = round( $value, $precision, WC_TAX_ROUNDING_MODE ); } else { // Fake it in PHP 5.2. - if ( 2 === WC_TAX_ROUNDING_MODE ) { + if ( 2 === WC_TAX_ROUNDING_MODE && strstr( $value, '.' ) ) { $value = (string) $value; $value = explode( '.', $value ); $value[1] = substr( $value[1], 0, $precision + 1 ); From a7b402b035f1f7235e0b8d9486541c9d4436dbe1 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 10 Aug 2017 13:08:30 -0300 Subject: [PATCH 12/15] Removed extra end of lines --- templates/checkout/order-receipt.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/templates/checkout/order-receipt.php b/templates/checkout/order-receipt.php index 21932a213f5..5a064c681b3 100644 --- a/templates/checkout/order-receipt.php +++ b/templates/checkout/order-receipt.php @@ -37,9 +37,7 @@ if ( ! defined( 'ABSPATH' ) ) { get_payment_method_title() ) : ?>
    • - get_payment_method_title() ); - ?> + get_payment_method_title() ); ?>
    From 51dffc08531c639b93a18cd084f5747d32781918 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 10 Aug 2017 17:24:27 +0100 Subject: [PATCH 13/15] Apply logical sort order to discounts Closes #16394 --- includes/class-wc-cart-totals.php | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/includes/class-wc-cart-totals.php b/includes/class-wc-cart-totals.php index 2362e1555b5..7311235c913 100644 --- a/includes/class-wc-cart-totals.php +++ b/includes/class-wc-cart-totals.php @@ -274,6 +274,39 @@ final class WC_Cart_Totals { */ protected function set_coupons() { $this->coupons = $this->object->get_coupons(); + + foreach ( $this->coupons as $coupon ) { + switch ( $coupon->get_discount_type() ) { + case 'fixed_product' : + $coupon->sort = 1; + break; + case 'percent' : + $coupon->sort = 2; + break; + case 'fixed_cart' : + $coupon->sort = 3; + break; + default: + $coupon->sort = 0; + break; + } + } + + uasort( $this->coupons, array( $this, 'sort_coupons' ) ); + } + + /** + * Sort coupons so discounts apply consistently. + * + * @param WC_Coupon $a + * @param WC_Coupon $b + * @return int + */ + protected function sort_coupons( $a, $b ) { + if ( $a->sort === $b->sort ) { + return $a->get_id() - $b->get_id(); + } + return ( $a->sort < $b->sort ) ? -1 : 1; } /** From fe05e090153c41034cd5a6099262c8ea0ff0f1db Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 10 Aug 2017 17:17:56 -0300 Subject: [PATCH 14/15] Skip title, description and exceprt sanitization and let WP handle it Should simulate the same behavior from WP admin, so just need to skip extra sanitization, so WP can handle it while salving with `wp_insert_post()` and `wp_update_post()` where will check for `unfiltered_html` capability. WP core already did something like it, but on REST API: https://core.trac.wordpress.org/ticket/38609 Fixes #16195 --- .../import/class-wc-product-csv-importer.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index fbc32877495..6ead8feff4e 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -442,6 +442,19 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { return ''; } + /** + * Just skip current field. + * + * By default is applied wc_clean() to all not listed fields + * in self::get_formating_callback(), use this method to skip any formating. + * + * @param string $value Field value. + * @return string + */ + public function parse_skip_field( $value ) { + return $value; + } + /** * Get formatting callback. * @@ -460,9 +473,9 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { 'featured' => array( $this, 'parse_bool_field' ), 'date_on_sale_from' => array( $this, 'parse_date_field' ), 'date_on_sale_to' => array( $this, 'parse_date_field' ), - 'name' => 'wp_filter_post_kses', - 'short_description' => 'wp_filter_post_kses', - 'description' => 'wp_filter_post_kses', + 'name' => array( $this, 'parse_skip_field' ), + 'short_description' => array( $this, 'parse_skip_field' ), + 'description' => array( $this, 'parse_skip_field' ), 'manage_stock' => array( $this, 'parse_bool_field' ), 'backorders' => array( $this, 'parse_backorders_field' ), 'stock_status' => array( $this, 'parse_bool_field' ), From a01ffdd11deabb8d988dd82c560730862ed6919d Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 10 Aug 2017 17:23:31 -0300 Subject: [PATCH 15/15] Better variable naming for importer parser methods --- .../import/class-wc-product-csv-importer.php | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index 6ead8feff4e..a8170a5f333 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -125,17 +125,17 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { * If mapping to a SKU and the product ID does not exist, a temporary object * will be created so it can be updated later. * - * @param string $field Field value. + * @param string $value Field value. * @return int|string */ - public function parse_relative_field( $field ) { + public function parse_relative_field( $value ) { global $wpdb; - if ( empty( $field ) ) { + if ( empty( $value ) ) { return ''; } - if ( preg_match( '/^id:(\d+)$/', $field, $matches ) ) { + if ( preg_match( '/^id:(\d+)$/', $value, $matches ) ) { $id = intval( $matches[1] ); $original_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_original_id' AND meta_value = %s;", $id ) ); @@ -154,15 +154,15 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { return $id; } - if ( $id = wc_get_product_id_by_sku( $field ) ) { + if ( $id = wc_get_product_id_by_sku( $value ) ) { return $id; } try { $product = new WC_Product_Simple(); - $product->set_name( 'Import placeholder for ' . $field ); + $product->set_name( 'Import placeholder for ' . $value ); $product->set_status( 'importing' ); - $product->set_sku( $field ); + $product->set_sku( $value ); $id = $product->save(); if ( $id && ! is_wp_error( $id ) ) { @@ -181,13 +181,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { * If we're not doing an update, create a placeholder product so mapping works * for rows following this one. * - * @param stirng $field + * @param string $value Field value. * @return int */ - public function parse_id_field( $field ) { + public function parse_id_field( $value ) { global $wpdb; - $id = absint( $field ); + $id = absint( $value ); if ( ! $id ) { return 0; @@ -225,77 +225,77 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { /** * Parse relative comma-delineated field and return product ID. * - * @param string $field Field value. + * @param string $value Field value. * @return array */ - public function parse_relative_comma_field( $field ) { - if ( empty( $field ) ) { + public function parse_relative_comma_field( $value ) { + if ( empty( $value ) ) { return array(); } - return array_filter( array_map( array( $this, 'parse_relative_field' ), $this->explode_values( $field ) ) ); + return array_filter( array_map( array( $this, 'parse_relative_field' ), $this->explode_values( $value ) ) ); } /** * Parse a comma-delineated field from a CSV. * - * @param string $field Field value. + * @param string $value Field value. * @return array */ - public function parse_comma_field( $field ) { - if ( empty( $field ) ) { + public function parse_comma_field( $value ) { + if ( empty( $value ) ) { return array(); } - return array_map( 'wc_clean', $this->explode_values( $field ) ); + return array_map( 'wc_clean', $this->explode_values( $value ) ); } /** * Parse a field that is generally '1' or '0' but can be something else. * - * @param string $field Field value. + * @param string $value Field value. * @return bool|string */ - public function parse_bool_field( $field ) { - if ( '0' === $field ) { + public function parse_bool_field( $value ) { + if ( '0' === $value ) { return false; } - if ( '1' === $field ) { + if ( '1' === $value ) { return true; } // Don't return explicit true or false for empty fields or values like 'notify'. - return wc_clean( $field ); + return wc_clean( $value ); } /** * Parse a float value field. * - * @param string $field Field value. + * @param string $value Field value. * @return float|string */ - public function parse_float_field( $field ) { - if ( '' === $field ) { - return $field; + public function parse_float_field( $value ) { + if ( '' === $value ) { + return $value; } - return floatval( $field ); + return floatval( $value ); } /** * Parse a category field from a CSV. * Categories are separated by commas and subcategories are "parent > subcategory". * - * @param string $field Field value. + * @param string $value Field value. * @return array of arrays with "parent" and "name" keys. */ - public function parse_categories_field( $field ) { - if ( empty( $field ) ) { + public function parse_categories_field( $value ) { + if ( empty( $value ) ) { return array(); } - $row_terms = $this->explode_values( $field ); + $row_terms = $this->explode_values( $value ); $categories = array(); foreach ( $row_terms as $row_term ) { @@ -332,15 +332,15 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { /** * Parse a tag field from a CSV. * - * @param string $field Field value. + * @param string $value Field value. * @return array */ - public function parse_tags_field( $field ) { - if ( empty( $field ) ) { + public function parse_tags_field( $value ) { + if ( empty( $value ) ) { return array(); } - $names = $this->explode_values( $field ); + $names = $this->explode_values( $value ); $tags = array(); foreach ( $names as $name ) { @@ -359,18 +359,18 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { /** * Parse a shipping class field from a CSV. * - * @param string $field Field value. + * @param string $value Field value. * @return int */ - public function parse_shipping_class_field( $field ) { - if ( empty( $field ) ) { + public function parse_shipping_class_field( $value ) { + if ( empty( $value ) ) { return 0; } - $term = get_term_by( 'name', $field, 'product_shipping_class' ); + $term = get_term_by( 'name', $value, 'product_shipping_class' ); if ( ! $term || is_wp_error( $term ) ) { - $term = (object) wp_insert_term( $field, 'product_shipping_class' ); + $term = (object) wp_insert_term( $value, 'product_shipping_class' ); } return $term->term_id; @@ -379,17 +379,17 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { /** * Parse images list from a CSV. Images can be filenames or URLs. * - * @param string $field Field value. + * @param string $value Field value. * @return array */ - public function parse_images_field( $field ) { - if ( empty( $field ) ) { + public function parse_images_field( $value ) { + if ( empty( $value ) ) { return array(); } $images = array(); - foreach ( $this->explode_values( $field ) as $image ) { + foreach ( $this->explode_values( $value ) as $image ) { if ( stristr( $image, '://' ) ) { $images[] = esc_url_raw( $image ); } else { @@ -404,17 +404,17 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { * Parse dates from a CSV. * Dates requires the format YYYY-MM-DD and time is optional. * - * @param string $field Field value. + * @param string $value Field value. * @return string|null */ - public function parse_date_field( $field ) { - if ( empty( $field ) ) { + public function parse_date_field( $value ) { + if ( empty( $value ) ) { return null; } - if ( preg_match( '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])([ 01-9:]*)$/', $field ) ) { + if ( preg_match( '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])([ 01-9:]*)$/', $value ) ) { // Don't include the time if the field had time in it. - return current( explode( ' ', $field ) ); + return current( explode( ' ', $value ) ); } return null; @@ -423,20 +423,20 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { /** * Parse backorders from a CSV. * - * @param string $field Field value. + * @param string $value Field value. * @return string */ - public function parse_backorders_field( $field ) { - if ( empty( $field ) ) { + public function parse_backorders_field( $value ) { + if ( empty( $value ) ) { return ''; } - $field = $this->parse_bool_field( $field ); + $value = $this->parse_bool_field( $value ); - if ( 'notify' === $field ) { + if ( 'notify' === $value ) { return 'notify'; - } elseif ( is_bool( $field ) ) { - return $field ? 'yes' : 'no'; + } elseif ( is_bool( $value ) ) { + return $value ? 'yes' : 'no'; } return '';