From 0fd11ad509ae5708731b3cc85f4ad722f57580fa Mon Sep 17 00:00:00 2001 From: Patrick Rauland Date: Mon, 24 Feb 2014 11:40:26 -0600 Subject: [PATCH 1/6] commenting regex in flat rate shipping --- .../shipping/flat-rate/class-wc-shipping-flat-rate.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php index 9be14d270ae..e429628d1bb 100644 --- a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php +++ b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php @@ -249,7 +249,15 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { $extra_rate['label'] = $this_option[0]; $this_cost = $this_option[1]; - if (preg_match('/(\d+\.?\d*)\s*(\+|-)\s*(\d+\.?\d*)\%/', $this_cost, $this_cost_matches)) { + $pattern = + '/' . // start regex + '(\d+\.?\d*)' . // capture digits, optionally capture a `.` and more digits + '\s*' . // match whitespace + '(\+|-)' . // capture the operand + '\s*'. // match whitespace + '(\d+\.?\d*)'. // capture digits, optionally capture a `.` and more digits + '\%/'; // match the percent sign & end regex + if ( preg_match( $pattern, $this_cost, $this_cost_matches ) ) { $this_cost_mathop = $this_cost_matches[2]; $this_cost_percents = $this_cost_matches[3] / 100; $this_cost = $this_cost_matches[1]; From cf81e63b3c08d7885ed8dbe2632e38e1c64f1334 Mon Sep 17 00:00:00 2001 From: Patrick Rauland Date: Mon, 24 Feb 2014 12:54:56 -0600 Subject: [PATCH 2/6] adding new method to calculate percentage rate adjustment for flat rate shipping --- .../flat-rate/class-wc-shipping-flat-rate.php | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php index 9be14d270ae..e8e0fc74f2b 100644 --- a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php +++ b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php @@ -273,12 +273,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { if ( $this_cost_percents ) { foreach ( $this->find_shipping_classes( $package ) as $shipping_class => $items ){ foreach ( $items as $item_id => $values ) { - if ($this_cost_mathop == '+') { - $this_cost += $this_cost_percents * $values['line_total']; - } - else { - $this_cost -= $this_cost_percents * $values['line_total']; - } + $this_cost = $this->calc_percentage_adjustment( $this_cost, $this_cost_percents, $this_cost_mathop, $values['line_total'] ); } } } @@ -289,24 +284,14 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { // Factor $this_cost by the percentage if provided. if ( $this_cost_percents ) { foreach ( $package['contents'] as $item_id => $values ) { - if ($this_cost_mathop == '+') { - $this_cost += $this_cost_percents * $values['line_total']; - } - else { - $this_cost -= $this_cost_percents * $values['line_total']; - } + $this_cost = $this->calc_percentage_adjustment( $this_cost, $this_cost_percents, $this_cost_mathop, $values['line_total'] ); } } break; case 'order' : // Factor $this_cost by the percentage if provided. if ( $this_cost_percents ) { - if ($this_cost_mathop == '+') { - $this_cost += $this_cost_percents * $package['contents_cost']; - } - else { - $this_cost -= $this_cost_percents * $package['contents_cost']; - } + $this_cost = $this->calc_percentage_adjustment( $this_cost, $this_cost_percents, $this_cost_mathop, $package['contents_cost'] ); } break; } @@ -323,6 +308,27 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { } + /** + * Calculate the percentage adjustment for each shipping rate. + * + * @access public + * @param float $cost + * @param float $percent_adjustment + * @param string $percent_operator + * @param float $base_price + * @return float + */ + function calc_percentage_adjustment( $cost, $percent_adjustment, $percent_operator, $base_price ) { + if ( '+' == $percent_operator ) { + $cost += $percent_adjustment * $base_price; + } else { + $cost -= $percent_adjustment * $base_price; + } + + return $cost; + } + + /** * order_shipping function. * From f3d1f5aa7d5cf5dea6fa459158f8cce53ab407cb Mon Sep 17 00:00:00 2001 From: Patrick Rauland Date: Mon, 24 Feb 2014 16:42:40 -0600 Subject: [PATCH 3/6] correcting cart template class names --- templates/cart/cart-item-data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/cart/cart-item-data.php b/templates/cart/cart-item-data.php index a77a5b5118d..9ab4685df3f 100644 --- a/templates/cart/cart-item-data.php +++ b/templates/cart/cart-item-data.php @@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly foreach ( $item_data as $data ) : $key = sanitize_text_field( $data['key'] ); ?> -
:
-
+
:
+
From 7b67161d2fd30e740b0ae64d8b8793a85a3ed2f9 Mon Sep 17 00:00:00 2001 From: Max Rice Date: Tue, 25 Feb 2014 01:02:38 -0500 Subject: [PATCH 4/6] Return request relative link headers, fixes #4925 When WordPress is running inside of a sub-directory, get_woocommerce_api_url() returns the domain along with the sub-directory path, which results in a duplicate path when the API request string is added. This commit fixes this by fetching only the home host and adding the request path to it. set_url_scheme() is used to set the scheme to either http or https based on the request itself instead of basing it on whether force_ssl_checkout is enabled or not. --- includes/api/class-wc-api-server.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/api/class-wc-api-server.php b/includes/api/class-wc-api-server.php index 8d78bf7bfd0..abba1b698d8 100644 --- a/includes/api/class-wc-api-server.php +++ b/includes/api/class-wc-api-server.php @@ -576,7 +576,7 @@ class WC_API_Server { } /** - * Returns the request URL with the page query parmeter set to the specified page + * Returns the request URL with the page query parameter set to the specified page * * @since 2.1 * @param int $page @@ -590,8 +590,10 @@ class WC_API_Server { // add provided page query param $request = urldecode( add_query_arg( 'page', $page, $request ) ); - // return full URL - return get_woocommerce_api_url( str_replace( '/wc-api/v1/', '', $request ) ); + // get the home host + $host = parse_url( get_home_url(), PHP_URL_HOST ); + + return set_url_scheme( "http://{$host}{$request}" ); } /** From 3d4f16a7a44a847258eea6a3cccfcb1840d59905 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 25 Feb 2014 11:40:49 +0000 Subject: [PATCH 5/6] Username from email hook Closes #4941 --- includes/shortcodes/class-wc-shortcode-my-account.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/shortcodes/class-wc-shortcode-my-account.php b/includes/shortcodes/class-wc-shortcode-my-account.php index 4c19cf808f7..6d764007f5c 100644 --- a/includes/shortcodes/class-wc-shortcode-my-account.php +++ b/includes/shortcodes/class-wc-shortcode-my-account.php @@ -212,7 +212,7 @@ class WC_Shortcode_My_Account { wc_add_notice( __( 'Enter a username or e-mail address.', 'woocommerce' ), 'error' ); - } elseif ( strpos( $_POST['user_login'], '@' ) ) { + } elseif ( strpos( $_POST['user_login'], '@' ) && apply_filters( 'woocommerce_get_username_from_email', true ) ) { $user_data = get_user_by( 'email', trim( $_POST['user_login'] ) ); @@ -223,7 +223,7 @@ class WC_Shortcode_My_Account { $login = trim( $_POST['user_login'] ); - $user_data = get_user_by('login', $login ); + $user_data = get_user_by( 'login', $login ); } do_action('lostpassword_post'); From 9a52c5dd435ce828a7d6fa17d4de7be74004fd51 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 25 Feb 2014 13:33:55 +0000 Subject: [PATCH 6/6] Combine two meta queries into one #4901 --- .../post-types/class-wc-admin-cpt-shop_order.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/includes/admin/post-types/class-wc-admin-cpt-shop_order.php b/includes/admin/post-types/class-wc-admin-cpt-shop_order.php index d7f086cca70..22b23f64e35 100644 --- a/includes/admin/post-types/class-wc-admin-cpt-shop_order.php +++ b/includes/admin/post-types/class-wc-admin-cpt-shop_order.php @@ -566,15 +566,6 @@ class WC_Admin_CPT_Shop_Order extends WC_Admin_CPT { // Search orders $post_ids = array_unique( array_merge( - $wpdb->get_col( - $wpdb->prepare( " - SELECT post_id - FROM {$wpdb->postmeta} - WHERE meta_key IN ('" . implode( "','", $search_fields ) . "') AND meta_value LIKE '%%%s%%' - ", - esc_attr( $_GET['s'] ) - ) - ), $wpdb->get_col( $wpdb->prepare( " SELECT p1.post_id @@ -584,8 +575,10 @@ class WC_Admin_CPT_Shop_Order extends WC_Admin_CPT { ( p1.meta_key = '_billing_first_name' AND p2.meta_key = '_billing_last_name' AND CONCAT(p1.meta_value, ' ', p2.meta_value) LIKE '%%%s%%' ) OR ( p1.meta_key = '_shipping_first_name' AND p2.meta_key = '_shipping_last_name' AND CONCAT(p1.meta_value, ' ', p2.meta_value) LIKE '%%%s%%' ) + OR + ( p1.meta_key IN ('" . implode( "','", $search_fields ) . "') AND p1.meta_value LIKE '%%%s%%' ) ", - esc_attr( $_GET['s'] ), esc_attr( $_GET['s'] ) + esc_attr( $_GET['s'] ), esc_attr( $_GET['s'] ), esc_attr( $_GET['s'] ) ) ), $wpdb->get_col(