Plugin Directory

Changeset 2102307


Ignore:
Timestamp:
06/07/2019 02:44:13 PM (7 years ago)
Author:
HappyKite
Message:

1.4.3 release

Location:
force-default-variant-for-woocommerce
Files:
8 added
3 edited

Legend:

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

    r2063740 r2102307  
    5454            'type'     => 'checkbox',
    5555            'desc'     => __( '<p>Respect the Product\'s Default if it is already set.</p>', 'hpy_wdv' ),
     56    );
     57   
     58    $settings_variant[] = array(
     59            'name'     => __( 'Disable auto-removal of \'Select Option\' text ', 'hpy_wdv' ),
     60            'desc_tip' => __( 'If you would like dropdowns to have the \'Select Option\' text by default when no product defaults are set, select this box. Force Default Variant options will still apply.', 'hpy_wdv' ),
     61            'id'       => 'hpy_disabled_auto_remove_dropdown',
     62            'std'     => 'no', // WooCommerce < 2.0
     63            'default' => 'no', // WooCommerce >= 2.0
     64            'type'     => 'checkbox',
     65            'desc'     => __( '<p>Re-enable \'Select Option\' text globally, manually set defaults will still apply.</p>', 'hpy_wdv' ),
    5666        );
    5767       
  • force-default-variant-for-woocommerce/trunk/includes/variations.php

    r2063740 r2102307  
    6666 */
    6767function hpy_fdv_remove_dropdown_option_html( $html, $args ) {
    68     if ( empty( $args['selected'] ) ) {
    69         return $html;
    70     }
    71    
     68  //Return normal html markup if disabled_auto_remove_dropdown is enabled.
     69    if ( empty( $args['selected'] ) && get_option('hpy_disabled_auto_remove_dropdown') == 'yes' ) {
     70    return $html;
     71  }
     72
    7273    $show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : __( 'Choose an option', 'woocommerce' );
    73     $show_option_none_html = '<option value="">' . esc_html( $show_option_none_text ) . '</option>';
    74    
    75     $html = str_replace($show_option_none_html, '', $html);
    76    
     74  $show_option_none_html = '<option value="">' . esc_html( $show_option_none_text ) . '</option>';
     75   
     76  $html = str_replace($show_option_none_html, '', $html);
     77  $html = preg_replace('/(<option\b[^><]*)>/i', '$1 class="attached enabled">', $html, 1); // Adds missing JS classes  -- Fixes the field appearing blank.
     78 
     79  // If no option selected by default, set first option to selected
     80  if ( empty( $args['selected'] )  ) {
     81    $html = preg_replace('/(<option\b[^><]*)>/i', '$1 selected>', $html, 1);
     82  }
     83
    7784    return $html;
    7885}
     
    112119
    113120        if ( $_child->get_status() == 'publish' ) {
    114             $attributes[] = array( 'price' => $_child->get_price(), 'id' => $_child->get_id(), 'position' => $position );
     121            $attributes[] = array( 'price' => !empty($_child->get_price()) ? $_child->get_price() : '0' , 'id' => $_child->get_id(), 'position' => $position );
    115122        }
    116123    }
     
    168175    $attributes = array_values($attributes);
    169176   
    170     $_prod = wc_get_product( $attributes[0]['id'] );
     177    $_prod = ! empty( $attributes[0]['id'] ) ? wc_get_product( $attributes[0]['id'] ) : null;
    171178   
    172179    if ( empty( $_prod ) ) {
  • force-default-variant-for-woocommerce/trunk/readme.txt

    r2063744 r2102307  
    33Tags: WooCommerce, Variable product, WooCommerce variant, eCommerce
    44Requires at least: 4.2
    5 Tested up to: 5.1.1
    6 Stable tag: 1.4.2
     5Tested up to: 5.2
     6Stable tag: 1.4.3
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2929
    3030== Changelog ==
     31= 1.4.3 =
     32* NEW - Select Option will now be removed from all product dropdown by default.
     33* NEW - Added new setting to toggle default 'Select Option' text
     34* FIX - Notice in /includes/variations.php:170
     35* FIX - Default selected option field being blank on page load due to missing JS classes.
     36* UPDATE - Now works with WordPress 5.2 and above.
    3137= 1.4.2 =
    3238* NEW - Adding in the ability to sort by Variant Position
Note: See TracChangeset for help on using the changeset viewer.