Merge pull request #4932 from BFTrick/flat-rate-costs-regex

Comment RegEx in Flat Rate Shipping
This commit is contained in:
Mike Jolley 2014-02-25 10:47:29 +00:00
commit b16f83804f
1 changed files with 9 additions and 1 deletions

View File

@ -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];