Changeset 3158888
- Timestamp:
- 09/27/2024 04:44:56 PM (18 months ago)
- Location:
- force-default-variant-for-woocommerce
- Files:
-
- 11 added
- 4 edited
-
tags/1.7/languages (added)
-
tags/1.8.1 (added)
-
tags/1.8.1/functions.php (added)
-
tags/1.8.1/includes (added)
-
tags/1.8.1/includes/clear-removal.php (added)
-
tags/1.8.1/includes/settings.php (added)
-
tags/1.8.1/includes/variations.php (added)
-
tags/1.8.1/languages (added)
-
tags/1.8.1/readme.txt (added)
-
tags/1.8.1/woo-force-default-variant.php (added)
-
tags/1.8/languages (added)
-
trunk/includes/settings.php (modified) (3 diffs)
-
trunk/includes/variations.php (modified) (13 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/woo-force-default-variant.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
force-default-variant-for-woocommerce/trunk/includes/settings.php
r2886515 r3158888 17 17 /** 18 18 * Check the current section is what we want 19 * */19 */ 20 20 if ( 'hpy_variants' === $current_section ) { 21 21 $settings_variant = array(); … … 39 39 'price-low' => __( 'Price Low -> High', 'force-default-variant-for-woocommerce' ), 40 40 'price-high' => __( 'Price High -> Low', 'force-default-variant-for-woocommerce' ), 41 'stock' => __( 'Stock Levels', 'force-default-variant-for-woocommerce' ), 41 42 ), 42 43 'css' => 'min-width:300px;', … … 94 95 /** 95 96 * If not, return the standard settings 96 * */97 */ 97 98 } else { 98 99 return $settings; 99 100 } 100 101 } 101 102 -
force-default-variant-for-woocommerce/trunk/includes/variations.php
r2985019 r3158888 32 32 $product_child = new WC_Product_Variation( $child ); 33 33 $prices[ $i ] = array( $product_child->get_price(), $to_use ); 34 $i ++;34 ++$i; 35 35 } 36 36 … … 50 50 51 51 return $args; 52 53 52 } 54 53 … … 126 125 127 126 if ( $hide_oos && ! $stock_status ) { 128 // If Hide out of Stock is set, and this variant is out of stock, then skip.127 // If Hide out of Stock is set, and this variant is out of stock, then skip. 129 128 continue; 130 129 } … … 141 140 'menu_order' => $menu_order, 142 141 'title' => $title, 142 'stock_count' => $stock_qty, 143 143 ) 144 144 ); … … 177 177 case 'alphabetically': 178 178 $attributes = hpy_fdv_multidimensional_sort( $attributes, 'alphabetically' ); 179 break; 180 181 case 'stock': 182 $attributes = hpy_fdv_multidimensional_sort( $attributes, 'stock' ); 179 183 break; 180 184 … … 249 253 } 250 254 251 function hpy_fdv_remove_element_by_value( $array, $key, $value){252 foreach ( $array as $subKey => $subArray) {253 if ( $subArray[$key] == $value) {254 unset( $array[$subKey]);255 function hpy_fdv_remove_element_by_value( $array, $key, $value ) { 256 foreach ( $array as $subKey => $subArray ) { 257 if ( $subArray[ $key ] == $value ) { 258 unset( $array[ $subKey ] ); 255 259 } 256 260 } … … 268 272 switch ( apply_filters( 'hpy_fdv_secondary_sort_switch', $sortby ) ) { 269 273 270 // Sort using the Secondary filter - Currently defaults to Position, so don't change anything if set to Position274 // Sort using the Secondary filter - Currently defaults to Position, so don't change anything if set to Position 271 275 case 'then_sales': 272 276 $split = hpy_fdv_multidimensional_sort( $split, 'sales' ); … … 293 297 294 298 return apply_filters( 'hpy_fdv_secondary_sort_filter', $attributes ); 295 296 299 } 297 300 … … 354 357 usort( 355 358 $array, 356 function ( $a, $b ) use ( $attribute ) {359 function ( $a, $b ) use ( $attribute ) { 357 360 return $a['menu_order'][ $attribute ] - $b['menu_order'][ $attribute ]; 358 361 } … … 360 363 } elseif ( 'alphabetically' === $check ) { 361 364 usort( $array, 'hpy_fdv_sort_alphabetically' ); 365 } elseif ( 'stock' === $check ) { 366 usort( $array, 'hpy_fdv_sort_stock' ); 362 367 } else { 363 368 usort( $array, 'hpy_fdv_sort_by_id' ); … … 365 370 366 371 return apply_filters( 'hpy_fdv_sort_filter', $array ); 367 368 372 } 369 373 … … 384 388 } 385 389 390 function hpy_fdv_sort_stock( $a, $b ) { 391 if ( $b['stock_count'] == $a['stock_count'] ) { 392 return 0; 393 } 394 return $b['stock_count'] < $a['stock_count'] ? -1 : 1; 395 } 396 386 397 function hpy_fdv_sort_by_attribute( $a, $b, $attribute ) { 387 398 return $a['id'][ $attribute ] - $b['id'][ $attribute ]; … … 397 408 $_primary = false; 398 409 foreach ( $attributes as $key => $value ) { 399 // Check for Primary Attribute. If not set, or multiple set, use first available Attribute.410 // Check for Primary Attribute. If not set, or multiple set, use first available Attribute. 400 411 $primary = get_post_meta( $parent->get_id(), 'attribute_' . $key . '_primary', true ); 401 412 if ( $primary ) { -
force-default-variant-for-woocommerce/trunk/readme.txt
r2985019 r3158888 3 3 Tags: WooCommerce, Variable product, WooCommerce variant, eCommerce 4 4 Requires at least: 4.2 5 Tested up to: 6. 3.26 Stable tag: 1.8 5 Tested up to: 6.6.2 6 Stable tag: 1.8.1 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 31 31 32 32 == Changelog == 33 = 1.8.1 - 28th September 2024 = 34 * NEW - Added Stock Count to the first Sort selection. 35 * UPDATE - Works with WooCommerce 9.3.3 36 * UPDATE - Works with WordPress 6.6.2 37 33 38 = 1.8 - 27th October 2023 = 34 39 * FIX - Issue with multiple attributes fixed -
force-default-variant-for-woocommerce/trunk/woo-force-default-variant.php
r2985019 r3158888 7 7 * Author URI: http://www.happykite.co.uk/ 8 8 * Text Domain: force-default-variant-for-woocommerce 9 * Version: 1.8 9 * Version: 1.8.1 10 10 * WC requires at least: 2.4 11 * WC tested up to: 8.2.111 * WC tested up to: 9.3.3 12 12 */ 13 13 … … 27 27 28 28 /*************************** 29 * includes30 ***************************/31 require dirname( __FILE__ ) . '/functions.php'; //Load Additional Functions32 require dirname( __FILE__ ) . '/includes/variations.php'; //Variant code33 require dirname( __FILE__ ) . '/includes/settings.php'; //Settings Area34 require dirname( __FILE__ ) . '/includes/clear-removal.php'; //Remove Clear Selection Text29 * includes 30 ***************************/ 31 require __DIR__ . '/functions.php'; // Load Additional Functions 32 require __DIR__ . '/includes/variations.php'; // Variant code 33 require __DIR__ . '/includes/settings.php'; // Settings Area 34 require __DIR__ . '/includes/clear-removal.php'; // Remove Clear Selection Text 35 35 36 36 37 37 /*************************** 38 * Get Current WC Version.39 ***************************/38 * Get Current WC Version. 39 ***************************/ 40 40 41 41 function hpy_check_wc_version() { 42 // Checking if get_plugins is available.42 // Checking if get_plugins is available. 43 43 if ( ! function_exists( 'get_plugins' ) ) { 44 44 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 45 45 } 46 46 47 // Adding required variables47 // Adding required variables 48 48 $woo_folder = get_plugins( '/woocommerce' ); 49 49 $woo_file = 'woocommerce.php'; 50 50 51 // Checking if Version number is set.51 // Checking if Version number is set. 52 52 if ( isset( $woo_folder[ $woo_file ]['Version'] ) ) { 53 53 return $woo_folder[ $woo_file ]['Version']; … … 55 55 return null; 56 56 } 57 58 57 } 59 58 60 59 /**************************** 61 60 * Declare HPOS Compatibility 62 * ***************************/61 */ 63 62 64 add_action( 'before_woocommerce_init', function() { 65 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { 66 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); 63 add_action( 64 'before_woocommerce_init', 65 function () { 66 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { 67 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); 68 } 67 69 } 68 });70 ); 69 71 70 72 71 73 /*************************** 72 74 * Activation Notice 73 * **************************/75 */ 74 76 $woo_version = hpy_check_wc_version(); 75 77 … … 112 114 113 115 /*************************** 114 * Adding Plugin Settings Link115 ***************************/116 * Adding Plugin Settings Link 117 ***************************/ 116 118 117 119 function hpy_fdv_settings_link( $links ) { … … 140 142 * @return void 141 143 */ 142 function hpy_fdv_check_for_wc_on_activation() : void {144 function hpy_fdv_check_for_wc_on_activation(): void { 143 145 if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) { 144 146 deactivate_plugins( plugin_basename( __FILE__ ) );
Note: See TracChangeset
for help on using the changeset viewer.