Changeset 2864952
- Timestamp:
- 02/14/2023 09:05:28 AM (3 years ago)
- Location:
- setary
- Files:
-
- 8 edited
- 1 copied
-
tags/1.2.0 (copied) (copied from setary/trunk)
-
tags/1.2.0/README.md (modified) (4 diffs)
-
tags/1.2.0/inc/class-product-controller.php (modified) (2 diffs)
-
tags/1.2.0/inc/class-products-with-variations.php (modified) (14 diffs)
-
tags/1.2.0/setary.php (modified) (2 diffs)
-
trunk/README.md (modified) (4 diffs)
-
trunk/inc/class-product-controller.php (modified) (2 diffs)
-
trunk/inc/class-products-with-variations.php (modified) (14 diffs)
-
trunk/setary.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
setary/tags/1.2.0/README.md
r2860720 r2864952 4 4 Requires at least: 5.7 5 5 Tested up to: 6.1.1 6 Requires PHP: 5.67 Stable tag: 1. 1.06 Requires PHP: 7.1 7 Stable tag: 1.2.0 8 8 License: MIT 9 9 License URI: https://opensource.org/licenses/MIT … … 18 18 Connect your WooCommerce store to Setary with this helper plugin and start bulk editing your WooCommerce products in a spreadsheet environment. 19 19 20 = Effortless Bulk Editing=21 Edit multiple product fields with ease using Setary, the ultimate solution for WooCommerce product management. Effortlessly update fields such as stock, prices, titles, descriptions, and custom fields in a matter of clicks.20 = Effortlessly Bulk Edit WooCommerce Products = 21 Edit multiple product fields with ease using Setary, the ultimate bulk product editor for WooCommerce. Effortlessly update fields such as stock, prices, titles, descriptions, and custom fields in a matter of clicks. 22 22 23 23 = Lightning-Fast = 24 Setary is super quick! Its API-driven bulk editing for WooCommerce means we remove all the strain off your server and deliver an unrivalled experience.24 Setary is super quick! Our WooCommerce bulk editor extends the WooCommerce API to alleviate server strain and deliver an unparalleled experience. 25 25 26 26 = Manage Multiple Stores = … … 28 28 29 29 = Push to Multiple Stores at Once = 30 If you have the same products in multiple WooCommerce stores, Setary makes it possible to update them all at the same time. Make your changes in our bulk spreadsheet editor on one store, then push those changes to multiple stores by matching products based on their Name, SKU, Slug, or ID.30 If you have the same products in multiple WooCommerce stores, Setary's bulk product editor makes it possible to update them all at the same time. Make your changes in our bulk product editor on one store, then push those changes to multiple stores by matching products based on their Name, SKU, Slug, or ID. 31 31 32 32 = Low-Cost Bulk Editing for WooCommerce = … … 61 61 62 62 == Changelog == 63 64 = v1.2.0 (2023-02-14) = 65 * [new] Enabled the "menu_order" field 66 * [new] Enabled the "width" field 67 * [new] Enabled the "height" field 68 * [new] Enabled the "length" field 69 * [new] Enabled the "shipping_class" field 70 * [new] Enabled the "weight" field 71 * [new] Enabled the "tax_class" field 72 * [new] Enabled the "tax_status" field 63 73 64 74 = v1.1.0 (2023-02-06) = -
setary/tags/1.2.0/inc/class-product-controller.php
r2860687 r2864952 41 41 } 42 42 43 if ( isset( $request['tax_class'] ) && 'standard' === $request['tex_class'] ) { 44 $product->set_tax_class( '' ); 45 } 46 43 47 if ( isset( $request['formatted_categories'] ) ) { 44 48 $category_ids = $this->get_term_ids( $request['formatted_categories'], 'product_cat' ); … … 60 64 $gallery_image_ids = wp_list_pluck( $images, 'id' ); 61 65 $product->set_gallery_image_ids( $gallery_image_ids ); 66 } 67 } 68 69 // These keys are not saved by default, so let's process them here. 70 71 $keys = [ 72 'width', 73 'height', 74 'length', 75 ]; 76 77 foreach( $keys as $key ) { 78 if( isset( $request[ $key ] ) ) { 79 $method_name = sprintf( 'set_%s', $key ); 80 81 if ( ! method_exists( $product, $method_name ) ) { 82 continue; 83 } 84 85 call_user_func( array( $product, $method_name ), $request[ $key ] ); 62 86 } 63 87 } -
setary/tags/1.2.0/inc/class-products-with-variations.php
r2860687 r2864952 132 132 // 31 => 'external_url', 133 133 // 32 => 'button_text', 134 //33 => 'tax_status',135 //34 => 'tax_class',134 33 => 'tax_status', 135 34 => 'tax_class', 136 136 35 => 'manage_stock', 137 137 36 => 'stock_quantity', … … 143 143 42 => 'sold_individually', 144 144 43 => 'weight', 145 //44 => 'dimensions',145 44 => 'dimensions', 146 146 // 45 => 'shipping_required', 147 147 // 46 => 'shipping_taxable', 148 //47 => 'shipping_class',148 47 => 'shipping_class', 149 149 // 48 => 'shipping_class_id', 150 150 // 49 => 'reviews_allowed', … … 163 163 // 62 => 'variations', 164 164 // 63 => 'grouped_products', 165 //64 => 'menu_order',165 64 => 'menu_order', 166 166 65 => 'meta_data', 167 167 ]; … … 169 169 $request->set_param( '_fields', $params ); 170 170 171 /** 172 * Ensure we get the variation image ID, and not the parent product image ID. 173 * 174 * @see WC_Product_Variation::get_image_id() 175 */ 176 add_filter( 'woocommerce_product_variation_get_image_id', function( $image_id, $product ) { 177 return $product->get_image_id( 'edit' ); 178 }, 10, 2 ); 171 $this->filter_variation_data(); 179 172 180 173 /** … … 184 177 185 178 return parent::get_product_data( $product, $context, $request ); 179 } 180 181 /** 182 * Filter variation data to ensure we're not 183 * getting data belonging to the parent product. 184 */ 185 public function filter_variation_data() { 186 $variation_data_keys = array( 187 'image_id', 188 'width', 189 'height', 190 'length', 191 'weight', 192 'shipping_class_id', 193 ); 194 195 foreach ( $variation_data_keys as $key ) { 196 add_filter( 'woocommerce_product_variation_get_' . $key, function( $value, $product ) use ( $key ) { 197 $method_name = 'get_' . $key; 198 199 if ( ! method_exists( $product, $method_name ) ) { 200 return $value; 201 } 202 203 return call_user_func( array( $product, $method_name ), 'edit' ); 204 }, 10, 2 ); 205 } 186 206 } 187 207 … … 206 226 $item['formatted_upsell_ids'] = $this->format_ids( $item['upsell_ids'] ); 207 227 $item['formatted_cross_sell_ids'] = $this->format_ids( $item['cross_sell_ids'] ); 228 $item['width'] = $this->get_dimension( $item, 'width'); 229 $item['height'] = $this->get_dimension( $item, 'height'); 230 $item['length'] = $this->get_dimension( $item, 'length'); 231 $item['tax_class'] = empty( $item['tax_class'] ) ? 'standard' : $item['tax_class']; 208 232 209 233 // If manage stock is "parent", then really it means "No". … … 247 271 $filter['from'] = 0; 248 272 } 249 if( empty( $filter['to'] ) ) { 250 $filter['to'] = PHP_INT_MAX; 273 274 if( empty( $filter['to'] ) && ( isset( $filter['to'] ) && '0' !== $filter['to'] ) ) { 275 $filter['to'] = $filter['from']; 251 276 } 252 277 … … 268 293 } 269 294 295 $numeric_post_fields = [ 296 'id' => 'ID', 297 'parent_id' => 'post_parent', 298 'menu_order' => 'menu_order', 299 ]; 300 301 // When searching by empty value, we need to use different query. 302 // Continue after adding filter. 270 303 if ( ! empty( $filter['mode'] ) && 'empty' === $filter['mode'] ) { 271 304 if( 'name' === $key ) { 272 305 add_filter( 'posts_where', [ new FilterByBetween(" AND ({$wpdb->prefix}posts.post_title IS NULL OR {$wpdb->prefix}posts.post_title = '')", array()), 'filter' ]); 306 } else if ( array_key_exists( $key, $numeric_post_fields ) ) { 307 $field = $numeric_post_fields[ $key ]; 308 add_filter( 'posts_where', [ new FilterByBetween(" AND (({$wpdb->prefix}posts.{$field} IS NULL OR {$wpdb->prefix}posts.{$field} = '') AND {$wpdb->prefix}posts.{$field} != 0)", array()), 'filter' ]); 273 309 } else if( 'slug' === $key ) { 274 310 add_filter( 'posts_where', [ new FilterByBetween(" AND ({$wpdb->prefix}posts.post_name IS NULL OR {$wpdb->prefix}posts.post_name = '')", array()), 'filter' ]); … … 290 326 ] 291 327 ); 292 } else if( in_array( $key, [ '_sku', '_regular_price', '_sale_price', '_stock' ], true) ) {293 $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.294 $query_args,295 [296 'relation' => 'OR',297 [298 'key' => $key,299 'value' => '',300 'compare' => '=',301 ],302 [303 'key' => $key,304 'value' => '0',305 'compare' => '=',306 ],307 [308 'key' => $key,309 'compare' => 'NOT EXISTS',310 'value' => 'null',311 ]312 ]313 );314 328 } else { 315 329 $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. 316 330 $query_args, 317 [ 318 'relation' => 'OR', 319 [ 320 'key' => $key, 321 'value' => '', 322 'compare' => '=', 323 ], 324 [ 325 'key' => $key, 326 'value' => '0', 327 'compare' => '=', 328 ], 329 [ 330 'key' => $key, 331 'compare' => 'NOT EXISTS', 332 'value' => 'null', 333 ] 334 ] 331 $this->get_empty_meta_query( $key ) 335 332 ); 336 333 } … … 338 335 } 339 336 340 if( 'id' === $key ) { 341 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.ID BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]); 337 // Otherwise, we can use standard query. 338 if ( array_key_exists( $key, $numeric_post_fields ) ) { 339 $field = $numeric_post_fields[ $key ]; 340 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.{$field} BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]); 342 341 } else if( 'type' === $key ) { 343 342 if( in_array( 'variation', $filter['query'], true ) ) { … … 353 352 ); 354 353 } 355 } else if( 'parent_id' === $key ) {356 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.post_parent BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);357 354 } else if( 'name' === $key ) { 358 355 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.post_title LIKE %s", array( '%' . $filter['query'] . '%' )), 'filter' ]); … … 463 460 ) 464 461 ); 465 } else if ( $filter['type'] === 'numeric' ) {462 } else if ( $filter['type'] === 'numeric' ) { 466 463 $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. 467 464 $query_args, 468 465 array( 469 466 'key' => $key, 470 'value' => array( floatval( $filter['from']), floatval($filter['to']) ),471 'compare' => 'BETWEEN',467 'value' => array( floatval( $filter['from'] ), floatval( $filter['to'] ) ), 468 'compare' => 'BETWEEN', 472 469 ) 470 ); 471 } 472 473 // Special case for tax_class. `'standard` is actually an empty string or not set. 474 if ( '_tax_class' === $key && in_array( 'standard', $filter['query'] ) ) { 475 $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. 476 $query_args, 477 $this->get_empty_meta_query( $key ), 478 'OR' 473 479 ); 474 480 } … … 535 541 return $response; 536 542 } 543 544 /** 545 * Get an empty meta query. 546 * 547 * @return array 548 */ 549 protected function get_empty_meta_query( $key ) { 550 return [ 551 'relation' => 'OR', 552 [ 553 'key' => $key, 554 'value' => '', 555 'compare' => '=', 556 ], 557 [ 558 'key' => $key, 559 'value' => '0', 560 'compare' => '=', 561 ], 562 [ 563 'key' => $key, 564 'compare' => 'NOT EXISTS', 565 'value' => 'null', 566 ], 567 ]; 568 } 537 569 538 570 /** … … 690 722 return implode( ', ', $ids ); 691 723 } 724 725 /** 726 * Get a specific product dimension. 727 * 728 * @param array $item Item array. 729 * @param string $key Key. 730 * 731 * @return string|float 732 */ 733 public function get_dimension( $item, $key ) { 734 if ( empty( $item['dimensions'] ) || empty( $item['dimensions'][ $key ] ) ) { 735 return ''; 736 } 737 738 return floatval( $item['dimensions'][ $key ] ); 739 } 740 741 /** 742 * Add meta query. 743 * 744 * @param array $args Query args. 745 * @param array $meta_query Meta query. 746 * @param string $relation 747 * 748 * @return array 749 */ 750 protected function add_meta_query( $args, $meta_query, $relation = 'AND' ) { 751 if ( empty( $args['meta_query'] ) ) { 752 $args['meta_query'] = array(); 753 } 754 755 $args['meta_query']['relation'] = $relation; 756 $args['meta_query'][] = $meta_query; 757 758 return $args['meta_query']; 759 } 692 760 } -
setary/tags/1.2.0/setary.php
r2860687 r2864952 11 11 * Author URI: https://setary.com/ 12 12 * 13 * Version: 1. 1.013 * Version: 1.2.0 14 14 * WC requires at least: 6.0.0 15 15 * WC tested up to: 7.3.0 … … 23 23 define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) ); 24 24 define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) ); 25 define( 'SETARY_VERSION', '1. 1.0' );25 define( 'SETARY_VERSION', '1.2.0' ); 26 26 define( 'SETARY_SITE_URL', 'https://setary.com/' ); 27 27 define( 'SETARY_APP_URL', 'https://setary.com/app/' ); -
setary/trunk/README.md
r2860720 r2864952 4 4 Requires at least: 5.7 5 5 Tested up to: 6.1.1 6 Requires PHP: 5.67 Stable tag: 1. 1.06 Requires PHP: 7.1 7 Stable tag: 1.2.0 8 8 License: MIT 9 9 License URI: https://opensource.org/licenses/MIT … … 18 18 Connect your WooCommerce store to Setary with this helper plugin and start bulk editing your WooCommerce products in a spreadsheet environment. 19 19 20 = Effortless Bulk Editing=21 Edit multiple product fields with ease using Setary, the ultimate solution for WooCommerce product management. Effortlessly update fields such as stock, prices, titles, descriptions, and custom fields in a matter of clicks.20 = Effortlessly Bulk Edit WooCommerce Products = 21 Edit multiple product fields with ease using Setary, the ultimate bulk product editor for WooCommerce. Effortlessly update fields such as stock, prices, titles, descriptions, and custom fields in a matter of clicks. 22 22 23 23 = Lightning-Fast = 24 Setary is super quick! Its API-driven bulk editing for WooCommerce means we remove all the strain off your server and deliver an unrivalled experience.24 Setary is super quick! Our WooCommerce bulk editor extends the WooCommerce API to alleviate server strain and deliver an unparalleled experience. 25 25 26 26 = Manage Multiple Stores = … … 28 28 29 29 = Push to Multiple Stores at Once = 30 If you have the same products in multiple WooCommerce stores, Setary makes it possible to update them all at the same time. Make your changes in our bulk spreadsheet editor on one store, then push those changes to multiple stores by matching products based on their Name, SKU, Slug, or ID.30 If you have the same products in multiple WooCommerce stores, Setary's bulk product editor makes it possible to update them all at the same time. Make your changes in our bulk product editor on one store, then push those changes to multiple stores by matching products based on their Name, SKU, Slug, or ID. 31 31 32 32 = Low-Cost Bulk Editing for WooCommerce = … … 61 61 62 62 == Changelog == 63 64 = v1.2.0 (2023-02-14) = 65 * [new] Enabled the "menu_order" field 66 * [new] Enabled the "width" field 67 * [new] Enabled the "height" field 68 * [new] Enabled the "length" field 69 * [new] Enabled the "shipping_class" field 70 * [new] Enabled the "weight" field 71 * [new] Enabled the "tax_class" field 72 * [new] Enabled the "tax_status" field 63 73 64 74 = v1.1.0 (2023-02-06) = -
setary/trunk/inc/class-product-controller.php
r2860687 r2864952 41 41 } 42 42 43 if ( isset( $request['tax_class'] ) && 'standard' === $request['tex_class'] ) { 44 $product->set_tax_class( '' ); 45 } 46 43 47 if ( isset( $request['formatted_categories'] ) ) { 44 48 $category_ids = $this->get_term_ids( $request['formatted_categories'], 'product_cat' ); … … 60 64 $gallery_image_ids = wp_list_pluck( $images, 'id' ); 61 65 $product->set_gallery_image_ids( $gallery_image_ids ); 66 } 67 } 68 69 // These keys are not saved by default, so let's process them here. 70 71 $keys = [ 72 'width', 73 'height', 74 'length', 75 ]; 76 77 foreach( $keys as $key ) { 78 if( isset( $request[ $key ] ) ) { 79 $method_name = sprintf( 'set_%s', $key ); 80 81 if ( ! method_exists( $product, $method_name ) ) { 82 continue; 83 } 84 85 call_user_func( array( $product, $method_name ), $request[ $key ] ); 62 86 } 63 87 } -
setary/trunk/inc/class-products-with-variations.php
r2860687 r2864952 132 132 // 31 => 'external_url', 133 133 // 32 => 'button_text', 134 //33 => 'tax_status',135 //34 => 'tax_class',134 33 => 'tax_status', 135 34 => 'tax_class', 136 136 35 => 'manage_stock', 137 137 36 => 'stock_quantity', … … 143 143 42 => 'sold_individually', 144 144 43 => 'weight', 145 //44 => 'dimensions',145 44 => 'dimensions', 146 146 // 45 => 'shipping_required', 147 147 // 46 => 'shipping_taxable', 148 //47 => 'shipping_class',148 47 => 'shipping_class', 149 149 // 48 => 'shipping_class_id', 150 150 // 49 => 'reviews_allowed', … … 163 163 // 62 => 'variations', 164 164 // 63 => 'grouped_products', 165 //64 => 'menu_order',165 64 => 'menu_order', 166 166 65 => 'meta_data', 167 167 ]; … … 169 169 $request->set_param( '_fields', $params ); 170 170 171 /** 172 * Ensure we get the variation image ID, and not the parent product image ID. 173 * 174 * @see WC_Product_Variation::get_image_id() 175 */ 176 add_filter( 'woocommerce_product_variation_get_image_id', function( $image_id, $product ) { 177 return $product->get_image_id( 'edit' ); 178 }, 10, 2 ); 171 $this->filter_variation_data(); 179 172 180 173 /** … … 184 177 185 178 return parent::get_product_data( $product, $context, $request ); 179 } 180 181 /** 182 * Filter variation data to ensure we're not 183 * getting data belonging to the parent product. 184 */ 185 public function filter_variation_data() { 186 $variation_data_keys = array( 187 'image_id', 188 'width', 189 'height', 190 'length', 191 'weight', 192 'shipping_class_id', 193 ); 194 195 foreach ( $variation_data_keys as $key ) { 196 add_filter( 'woocommerce_product_variation_get_' . $key, function( $value, $product ) use ( $key ) { 197 $method_name = 'get_' . $key; 198 199 if ( ! method_exists( $product, $method_name ) ) { 200 return $value; 201 } 202 203 return call_user_func( array( $product, $method_name ), 'edit' ); 204 }, 10, 2 ); 205 } 186 206 } 187 207 … … 206 226 $item['formatted_upsell_ids'] = $this->format_ids( $item['upsell_ids'] ); 207 227 $item['formatted_cross_sell_ids'] = $this->format_ids( $item['cross_sell_ids'] ); 228 $item['width'] = $this->get_dimension( $item, 'width'); 229 $item['height'] = $this->get_dimension( $item, 'height'); 230 $item['length'] = $this->get_dimension( $item, 'length'); 231 $item['tax_class'] = empty( $item['tax_class'] ) ? 'standard' : $item['tax_class']; 208 232 209 233 // If manage stock is "parent", then really it means "No". … … 247 271 $filter['from'] = 0; 248 272 } 249 if( empty( $filter['to'] ) ) { 250 $filter['to'] = PHP_INT_MAX; 273 274 if( empty( $filter['to'] ) && ( isset( $filter['to'] ) && '0' !== $filter['to'] ) ) { 275 $filter['to'] = $filter['from']; 251 276 } 252 277 … … 268 293 } 269 294 295 $numeric_post_fields = [ 296 'id' => 'ID', 297 'parent_id' => 'post_parent', 298 'menu_order' => 'menu_order', 299 ]; 300 301 // When searching by empty value, we need to use different query. 302 // Continue after adding filter. 270 303 if ( ! empty( $filter['mode'] ) && 'empty' === $filter['mode'] ) { 271 304 if( 'name' === $key ) { 272 305 add_filter( 'posts_where', [ new FilterByBetween(" AND ({$wpdb->prefix}posts.post_title IS NULL OR {$wpdb->prefix}posts.post_title = '')", array()), 'filter' ]); 306 } else if ( array_key_exists( $key, $numeric_post_fields ) ) { 307 $field = $numeric_post_fields[ $key ]; 308 add_filter( 'posts_where', [ new FilterByBetween(" AND (({$wpdb->prefix}posts.{$field} IS NULL OR {$wpdb->prefix}posts.{$field} = '') AND {$wpdb->prefix}posts.{$field} != 0)", array()), 'filter' ]); 273 309 } else if( 'slug' === $key ) { 274 310 add_filter( 'posts_where', [ new FilterByBetween(" AND ({$wpdb->prefix}posts.post_name IS NULL OR {$wpdb->prefix}posts.post_name = '')", array()), 'filter' ]); … … 290 326 ] 291 327 ); 292 } else if( in_array( $key, [ '_sku', '_regular_price', '_sale_price', '_stock' ], true) ) {293 $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.294 $query_args,295 [296 'relation' => 'OR',297 [298 'key' => $key,299 'value' => '',300 'compare' => '=',301 ],302 [303 'key' => $key,304 'value' => '0',305 'compare' => '=',306 ],307 [308 'key' => $key,309 'compare' => 'NOT EXISTS',310 'value' => 'null',311 ]312 ]313 );314 328 } else { 315 329 $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. 316 330 $query_args, 317 [ 318 'relation' => 'OR', 319 [ 320 'key' => $key, 321 'value' => '', 322 'compare' => '=', 323 ], 324 [ 325 'key' => $key, 326 'value' => '0', 327 'compare' => '=', 328 ], 329 [ 330 'key' => $key, 331 'compare' => 'NOT EXISTS', 332 'value' => 'null', 333 ] 334 ] 331 $this->get_empty_meta_query( $key ) 335 332 ); 336 333 } … … 338 335 } 339 336 340 if( 'id' === $key ) { 341 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.ID BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]); 337 // Otherwise, we can use standard query. 338 if ( array_key_exists( $key, $numeric_post_fields ) ) { 339 $field = $numeric_post_fields[ $key ]; 340 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.{$field} BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]); 342 341 } else if( 'type' === $key ) { 343 342 if( in_array( 'variation', $filter['query'], true ) ) { … … 353 352 ); 354 353 } 355 } else if( 'parent_id' === $key ) {356 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.post_parent BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);357 354 } else if( 'name' === $key ) { 358 355 add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.post_title LIKE %s", array( '%' . $filter['query'] . '%' )), 'filter' ]); … … 463 460 ) 464 461 ); 465 } else if ( $filter['type'] === 'numeric' ) {462 } else if ( $filter['type'] === 'numeric' ) { 466 463 $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. 467 464 $query_args, 468 465 array( 469 466 'key' => $key, 470 'value' => array( floatval( $filter['from']), floatval($filter['to']) ),471 'compare' => 'BETWEEN',467 'value' => array( floatval( $filter['from'] ), floatval( $filter['to'] ) ), 468 'compare' => 'BETWEEN', 472 469 ) 470 ); 471 } 472 473 // Special case for tax_class. `'standard` is actually an empty string or not set. 474 if ( '_tax_class' === $key && in_array( 'standard', $filter['query'] ) ) { 475 $query_args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. 476 $query_args, 477 $this->get_empty_meta_query( $key ), 478 'OR' 473 479 ); 474 480 } … … 535 541 return $response; 536 542 } 543 544 /** 545 * Get an empty meta query. 546 * 547 * @return array 548 */ 549 protected function get_empty_meta_query( $key ) { 550 return [ 551 'relation' => 'OR', 552 [ 553 'key' => $key, 554 'value' => '', 555 'compare' => '=', 556 ], 557 [ 558 'key' => $key, 559 'value' => '0', 560 'compare' => '=', 561 ], 562 [ 563 'key' => $key, 564 'compare' => 'NOT EXISTS', 565 'value' => 'null', 566 ], 567 ]; 568 } 537 569 538 570 /** … … 690 722 return implode( ', ', $ids ); 691 723 } 724 725 /** 726 * Get a specific product dimension. 727 * 728 * @param array $item Item array. 729 * @param string $key Key. 730 * 731 * @return string|float 732 */ 733 public function get_dimension( $item, $key ) { 734 if ( empty( $item['dimensions'] ) || empty( $item['dimensions'][ $key ] ) ) { 735 return ''; 736 } 737 738 return floatval( $item['dimensions'][ $key ] ); 739 } 740 741 /** 742 * Add meta query. 743 * 744 * @param array $args Query args. 745 * @param array $meta_query Meta query. 746 * @param string $relation 747 * 748 * @return array 749 */ 750 protected function add_meta_query( $args, $meta_query, $relation = 'AND' ) { 751 if ( empty( $args['meta_query'] ) ) { 752 $args['meta_query'] = array(); 753 } 754 755 $args['meta_query']['relation'] = $relation; 756 $args['meta_query'][] = $meta_query; 757 758 return $args['meta_query']; 759 } 692 760 } -
setary/trunk/setary.php
r2860687 r2864952 11 11 * Author URI: https://setary.com/ 12 12 * 13 * Version: 1. 1.013 * Version: 1.2.0 14 14 * WC requires at least: 6.0.0 15 15 * WC tested up to: 7.3.0 … … 23 23 define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) ); 24 24 define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) ); 25 define( 'SETARY_VERSION', '1. 1.0' );25 define( 'SETARY_VERSION', '1.2.0' ); 26 26 define( 'SETARY_SITE_URL', 'https://setary.com/' ); 27 27 define( 'SETARY_APP_URL', 'https://setary.com/app/' );
Note: See TracChangeset
for help on using the changeset viewer.