PluginProbe
Tiered Pricing Table for WooCommerce / 8.1.0
Tiered Pricing Table for WooCommerce v8.1.0
8.1.0 8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 All 92 releases
← All changes | src/Addons/ImportExport/WoocommerceImportService.php +11 -8 6.5.0 → 8.1.0 View file →
@@ -82,22 +82,25 @@
82 82 return $product;
83 83 }
84 84
85 85 /**
86 - * Decode export string format to array of pricing rules
86 + * Decode the export string format ("10:90,20:80") into an array of pricing rules.
87 + *
88 + * Each rule is "quantity:price" (or "quantity=price", which spreadsheets leave alone, while they
89 + * turn "20:100" into a time). Anything else, for example a cell a spreadsheet already turned
90 + * into "21:40:00", is ignored instead of being imported as a wrong tier.
87 91 */
88 92 public static function decodeExport( string $data ): array {
89 93 $rules = explode( TierPricingTablePlugin::getRulesSeparator(), $data );
90 94
95 + // ":" and "=" always work; a store may export with another separator through the filter.
96 + $separators = preg_quote( ':=' . TierPricingTablePlugin::getRuleSeparator(), '/' );
97 +
91 98 $data = array();
92 99
93 - if ( $rules ) {
94 - foreach ( $rules as $rule ) {
95 - $rule = explode( ':', $rule );
96 -
97 - if ( isset( $rule[0] ) && isset( $rule[1] ) ) {
98 - $data[ intval( $rule[0] ) ] = $rule[1];
99 - }
100 + foreach ( $rules as $rule ) {
101 + if ( preg_match( '/^\s*(\d+)\s*[' . $separators . ']\s*(\d+(?:\.\d+)?)\s*$/', $rule, $matches ) ) {
102 + $data[ intval( $matches[1] ) ] = $matches[2];
100 103 }
101 104 }
102 105
103 106 $data = array_filter( $data );