Plugin Directory

Changeset 3158888


Ignore:
Timestamp:
09/27/2024 04:44:56 PM (18 months ago)
Author:
HappyKite
Message:

Version 1.8.1 released

Location:
force-default-variant-for-woocommerce
Files:
11 added
4 edited

Legend:

Unmodified
Added
Removed
  • force-default-variant-for-woocommerce/trunk/includes/settings.php

    r2886515 r3158888  
    1717    /**
    1818     * Check the current section is what we want
    19      **/
     19     */
    2020    if ( 'hpy_variants' === $current_section ) {
    2121        $settings_variant = array();
     
    3939                'price-low'      => __( 'Price Low -> High', 'force-default-variant-for-woocommerce' ),
    4040                'price-high'     => __( 'Price High -> Low', 'force-default-variant-for-woocommerce' ),
     41                'stock'          => __( 'Stock Levels', 'force-default-variant-for-woocommerce' ),
    4142            ),
    4243            'css'      => 'min-width:300px;',
     
    9495        /**
    9596         * If not, return the standard settings
    96          **/
     97         */
    9798    } else {
    9899        return $settings;
    99100    }
    100101}
    101 
    102 
  • force-default-variant-for-woocommerce/trunk/includes/variations.php

    r2985019 r3158888  
    3232            $product_child = new WC_Product_Variation( $child );
    3333            $prices[ $i ]  = array( $product_child->get_price(), $to_use );
    34             $i ++;
     34            ++$i;
    3535        }
    3636
     
    5050
    5151    return $args;
    52 
    5352}
    5453
     
    126125
    127126        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.
    129128            continue;
    130129        }
     
    141140                    'menu_order'  => $menu_order,
    142141                    'title'       => $title,
     142                    'stock_count' => $stock_qty,
    143143                )
    144144            );
     
    177177        case 'alphabetically':
    178178            $attributes = hpy_fdv_multidimensional_sort( $attributes, 'alphabetically' );
     179            break;
     180
     181        case 'stock':
     182            $attributes = hpy_fdv_multidimensional_sort( $attributes, 'stock' );
    179183            break;
    180184
     
    249253}
    250254
    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]);
     255function hpy_fdv_remove_element_by_value( $array, $key, $value ) {
     256    foreach ( $array as $subKey => $subArray ) {
     257        if ( $subArray[ $key ] == $value ) {
     258            unset( $array[ $subKey ] );
    255259        }
    256260    }
     
    268272        switch ( apply_filters( 'hpy_fdv_secondary_sort_switch', $sortby ) ) {
    269273
    270             //Sort using the Secondary filter - Currently defaults to Position, so don't change anything if set to Position
     274            // Sort using the Secondary filter - Currently defaults to Position, so don't change anything if set to Position
    271275            case 'then_sales':
    272276                $split = hpy_fdv_multidimensional_sort( $split, 'sales' );
     
    293297
    294298    return apply_filters( 'hpy_fdv_secondary_sort_filter', $attributes );
    295 
    296299}
    297300
     
    354357        usort(
    355358            $array,
    356             function( $a, $b ) use ( $attribute ) {
     359            function ( $a, $b ) use ( $attribute ) {
    357360                return $a['menu_order'][ $attribute ] - $b['menu_order'][ $attribute ];
    358361            }
     
    360363    } elseif ( 'alphabetically' === $check ) {
    361364        usort( $array, 'hpy_fdv_sort_alphabetically' );
     365    } elseif ( 'stock' === $check ) {
     366        usort( $array, 'hpy_fdv_sort_stock' );
    362367    } else {
    363368        usort( $array, 'hpy_fdv_sort_by_id' );
     
    365370
    366371    return apply_filters( 'hpy_fdv_sort_filter', $array );
    367 
    368372}
    369373
     
    384388}
    385389
     390function 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
    386397function hpy_fdv_sort_by_attribute( $a, $b, $attribute ) {
    387398    return $a['id'][ $attribute ] - $b['id'][ $attribute ];
     
    397408    $_primary = false;
    398409    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.
    400411        $primary = get_post_meta( $parent->get_id(), 'attribute_' . $key . '_primary', true );
    401412        if ( $primary ) {
  • force-default-variant-for-woocommerce/trunk/readme.txt

    r2985019 r3158888  
    33Tags: WooCommerce, Variable product, WooCommerce variant, eCommerce
    44Requires at least: 4.2
    5 Tested up to: 6.3.2
    6 Stable tag: 1.8
     5Tested up to: 6.6.2
     6Stable tag: 1.8.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3131
    3232== 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
    3338= 1.8 - 27th October 2023 =
    3439* FIX - Issue with multiple attributes fixed
  • force-default-variant-for-woocommerce/trunk/woo-force-default-variant.php

    r2985019 r3158888  
    77 * Author URI: http://www.happykite.co.uk/
    88 * Text Domain: force-default-variant-for-woocommerce
    9  * Version: 1.8
     9 * Version: 1.8.1
    1010 * WC requires at least: 2.4
    11  * WC tested up to: 8.2.1
     11 * WC tested up to: 9.3.3
    1212 */
    1313
     
    2727
    2828/***************************
    29 * includes
    30 ***************************/
    31 require dirname( __FILE__ ) . '/functions.php'; //Load Additional Functions
    32 require dirname( __FILE__ ) . '/includes/variations.php'; //Variant code
    33 require dirname( __FILE__ ) . '/includes/settings.php'; //Settings Area
    34 require dirname( __FILE__ ) . '/includes/clear-removal.php'; //Remove Clear Selection Text
     29 * includes
     30 ***************************/
     31require __DIR__ . '/functions.php'; // Load Additional Functions
     32require __DIR__ . '/includes/variations.php'; // Variant code
     33require __DIR__ . '/includes/settings.php'; // Settings Area
     34require __DIR__ . '/includes/clear-removal.php'; // Remove Clear Selection Text
    3535
    3636
    3737/***************************
    38 * Get Current WC Version.
    39 ***************************/
     38 * Get Current WC Version.
     39 ***************************/
    4040
    4141function hpy_check_wc_version() {
    42     //Checking if get_plugins is available.
     42    // Checking if get_plugins is available.
    4343    if ( ! function_exists( 'get_plugins' ) ) {
    4444        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    4545    }
    4646
    47     //Adding required variables
     47    // Adding required variables
    4848    $woo_folder = get_plugins( '/woocommerce' );
    4949    $woo_file   = 'woocommerce.php';
    5050
    51     //Checking if Version number is set.
     51    // Checking if Version number is set.
    5252    if ( isset( $woo_folder[ $woo_file ]['Version'] ) ) {
    5353        return $woo_folder[ $woo_file ]['Version'];
     
    5555        return null;
    5656    }
    57 
    5857}
    5958
    6059/****************************
    6160 * Declare HPOS Compatibility
    62  ****************************/
     61 */
    6362
    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 );
     63add_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        }
    6769    }
    68 } );
     70);
    6971
    7072
    7173/***************************
    7274* Activation Notice
    73 ***************************/
     75*/
    7476$woo_version = hpy_check_wc_version();
    7577
     
    112114
    113115/***************************
    114 * Adding Plugin Settings Link
    115 ***************************/
     116 * Adding Plugin Settings Link
     117 ***************************/
    116118
    117119function hpy_fdv_settings_link( $links ) {
     
    140142 * @return void
    141143 */
    142 function hpy_fdv_check_for_wc_on_activation() : void {
     144function hpy_fdv_check_for_wc_on_activation(): void {
    143145    if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
    144146        deactivate_plugins( plugin_basename( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.