Plugin Directory

Changeset 3458839


Ignore:
Timestamp:
02/11/2026 09:55:32 AM (6 weeks ago)
Author:
elextensions
Message:

updated to v4.1.9

Location:
elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce
Files:
26 edited
1 copied

Legend:

Unmodified
Added
Removed
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/assets/js/req_script.js

    r3019704 r3458839  
    2323    jQuery(function(){
    2424
    25         if (jQuery('#elex_ppct_discount_type').val() === 'no-discount') {
    26             jQuery('#elex_ppct_discount_amount').closest('tr').addClass('d-none');
    27         }
    28 
    2925        // On change event of the discount type dropdown
    3026        jQuery('#elex_ppct_discount_type').change(function() {
    31             if (jQuery(this).val() === 'no-discount') {
     27            const selectedVal = jQuery(this).val();
     28            const $amountField = jQuery('#elex_ppct_discount_amount');
     29            if (selectedVal === 'no-discount') {
    3230                // If "No Discount" is selected, hide the discount value field
    33                 jQuery('#elex_ppct_discount_amount').closest('tr').addClass('d-none');
     31                $amountField.closest('tr').addClass('d-none');
    3432            } else {
    3533                // If any other option is selected, show the discount value field
    36                 jQuery('#elex_ppct_discount_amount').closest('tr').removeClass('d-none');
    37             }
    38         });
     34                $amountField.closest('tr').removeClass('d-none');
     35                if (selectedVal === 'percent') {
     36                    $amountField.attr('max', 100);
     37                    if ($amountField.val() > 100) {
     38                        $amountField.val(100);
     39                    }
     40                } else {
     41                    $amountField.removeAttr('max');
     42                }
     43            }
     44        }).trigger('change');
    3945
    4046        //include products filter
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/assets/js/settings.js

    r3019704 r3458839  
    481481
    482482jQuery('.general_setting_save_chages').click(function(){
    483     if( jQuery('#exclude_product_enabled').prop('checked') ) {
    484          if(jQuery('.exclude_prod_by_cat').select2('data').length === 0 &&
    485         jQuery('.exclude_prod_by_name').select2('data').length === 0 &&
    486         jQuery('.exclude_prod_by_tag').select2('data').length === 0 ){
    487             alert("Choose any options for exclude category or tag or name");
     483    // while percentage discount is enabled discount percentage should be between 0 to 100
     484    if (jQuery('#elex_ppct_discount_type').val() === 'percent') {
     485        const discount_value = jQuery('#elex_ppct_discount_amount').val();
     486        if (discount_value < 0 || discount_value > 100) {
     487            alert("Enter valid discount percentage");
    488488            return false;
    489489        }
    490        
    491     }
    492     if( jQuery('#limit_product_is_enabled').prop('checked') ) {
    493         if(jQuery('.include_prod_by_cat').select2('data').length === 0 &&
    494        jQuery('.include_prod_by_name').select2('data').length === 0 &&
    495        jQuery('.include_prod_by_tag').select2('data').length === 0 ){
    496            alert("Choose any options for include category or tag or name");
    497            return false;
    498        }
    499        
    500    }
    501    
    502 
    503    if( jQuery('#role_based_enabled').prop('checked') ) {
    504     if(jQuery('.include_roles').select2('data').length === 0 &&
    505    jQuery('.exclude_roles').select2('data').length === 0 ){
    506        alert("Choose any options for user role.");
    507        return false;
    508    }
    509    
    510 }
    511 
    512 if( jQuery('#hide_add_cart_exclude').prop('checked') ) {
    513     if(jQuery('.hidecart_exclude_prod_by_cat').select2('data').length === 0 &&
    514    jQuery('.hidecart_exclude_prod_by_name').select2('data').length === 0 &&
    515    jQuery('.hidecart_exclude_prod_by_tag').select2('data').length === 0 ){
    516        alert("Choose any options for exclude category or tag or name");
    517        return false;
    518    }
    519  
    520 }
    521 
    522 
     490    }
    523491});
    524492jQuery('.hidecart_setting_save_chages').click(function(){
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/elex-woocommerce-product-price-custom-text-discount.php

    r3383764 r3458839  
    44Plugin URI: https://elextensions.com/plugin
    55Description: The plugin simplifies the task to add a text before and after the product price both globally and individually.It also allows you to apply a quick discount for your products.
    6 Version: 4.1.8
     6Version: 4.1.9
    77WC requires at least: 2.6.0
    88WC tested up to: 10.0.0
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/includes/SettingsController.php

    r3298807 r3458839  
    154154    // to get the base price of the product.
    155155    public static function elex_ppct_base_price( $product ) {
    156     remove_filter( 'woocommerce_product_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    157    remove_filter( 'woocommerce_product_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    158 
    159    remove_filter( 'woocommerce_product_variation_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    160    remove_filter( 'woocommerce_product_variation_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    161 
    162    $base_price = $product->get_regular_price();
    163    // for simple product price.
    164    add_filter( 'woocommerce_product_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    165    add_filter( 'woocommerce_product_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    166 
    167    // for variable product each variation price.
    168    add_filter( 'woocommerce_product_variation_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    169    add_filter( 'woocommerce_product_variation_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    170 
    171    return $base_price;
     156        // remove the price filters to get the base price
     157        self::remove_price_filters();
     158
     159        // get the base price
     160        $base_price = $product->get_regular_price();
     161
     162        // add the price filters
     163        self::add_price_filters();
     164
     165        return $base_price;
    172166    }
    173167
     
    415409        if ( 'amount' === $type && is_numeric( $price ) ) {
    416410            $price = ( $price - ( ( float ) $discount ) );
     411            if ( $price < 0 ) {
     412                $price = 0;
     413            }
    417414        }
    418415        if ( 'percent' === $type && is_numeric( $price ) ) {
    419416            $price = ( $price - ( $price * ( ( float ) $discount / 100 ) ) );
     417            if ( $price < 0 ) {
     418                $price = 0;
     419            }
    420420        }
    421421    return $price;
     
    430430            $product_id = $product->get_id();
    431431        }
    432        
    433432        $product_info = wc_get_product( $product_id );
     433       
     434        // Prevent Recursion: Remove filters before querying product data
     435        self::remove_price_filters();
     436
     437        //fetch product data
     438        $is_on_sale = $product->is_on_sale();
     439       
     440        // Restore filters immediately
     441        self::add_price_filters();
     442        $current_hook = current_filter();
     443       
     444        // while applying this plugin's discount, no need to change/apply discount on regular price if product is on sale,
     445        if ( strpos( $current_hook, 'regular_price' ) !== false && $is_on_sale ) {
     446            return $price;
     447        }
     448
    434449        $custom_check_enable = 'no';
    435450        $custom_discount_checkbox = 'no';
    436 
    437451        if ( is_object( $product_info ) && method_exists( $product_info, 'get_meta' ) ) {
    438452            $custom_check_enable = $product_info->get_meta( 'elex_ppct_custom_fields_checkbox' ) ? $product_info->get_meta( 'elex_ppct_custom_fields_checkbox' ) : 'no';
    439453            $custom_discount_checkbox = $product_info->get_meta( 'elex_ppct_custom_fields_discount_type_checkbox' ) ? $product_info->get_meta( 'elex_ppct_custom_fields_discount_type_checkbox' ) : 'no';
    440454        }
    441        
    442 
    443         $check_enable             = get_option( 'elex_ppct_check_field' );
     455        $check_enable = get_option( 'elex_ppct_check_field' );
    444456
    445457        if ( ! empty( $variation_id ) ) {
     
    851863        $new_settings['elex_ppct_check_field']                                                       = isset( $_POST['elex_ppct_check_field'] ) ? true : false;
    852864
    853         $new_settings['general']['limit_button_on_certain_products']['enabled']                      = isset( $_POST['general']['limit_button_on_certain_products']['enabled'] ) ? true : false;
    854         $new_settings['general']['limit_button_on_certain_products']['select_all']                   = isset( $_POST['general']['limit_button_on_certain_products']['select_all'] ) ? true : false;
    855         $new_settings['general']['limit_button_on_certain_products']['include_products_by_category'] = isset( $_POST['general']['limit_button_on_certain_products']['include_products_by_category'] ) ? map_deep( $_POST['general']['limit_button_on_certain_products']['include_products_by_category'], 'sanitize_text_field' ) : array();
    856         $new_settings['general']['limit_button_on_certain_products']['include_products_by_name']     = isset( $_POST['general']['limit_button_on_certain_products']['include_products_by_name'] ) ? map_deep( $_POST['general']['limit_button_on_certain_products']['include_products_by_name'], 'sanitize_text_field' ) : array();
    857         $new_settings['general']['limit_button_on_certain_products']['include_products_by_tag']      = isset( $_POST['general']['limit_button_on_certain_products']['include_products_by_tag'] ) ? map_deep( $_POST['general']['limit_button_on_certain_products']['include_products_by_tag'], 'sanitize_text_field' ) : array();
    858        
    859         $new_settings['general']['exclude_products']['enabled']                                      = isset( $_POST['general']['exclude_products']['enabled'] ) ? true : false;
    860         $new_settings['general']['exclude_products']['select_all']                                   = isset( $_POST['general']['exclude_products']['select_all'] ) ? true : false;
    861         $new_settings['general']['exclude_products']['by_category']                                  = isset( $_POST['general']['exclude_products']['by_category'] ) ? map_deep( $_POST['general']['exclude_products']['by_category'], 'sanitize_text_field' ) : array();
    862         $new_settings['general']['exclude_products']['by_name']                                      = isset( $_POST['general']['exclude_products']['by_name'] ) ? map_deep( $_POST['general']['exclude_products']['by_name'], 'sanitize_text_field' ) : array();
    863         $new_settings['general']['exclude_products']['by_tag']                                       = isset( $_POST['general']['exclude_products']['by_tag'] ) ? map_deep( $_POST['general']['exclude_products']['by_tag'], 'sanitize_text_field' ) : array();
    864        
    865         $new_settings['general']['role_based_filter']['enabled']                                     = isset( $_POST['general']['role_based_filter']['enabled'] ) ? true : false;
    866         $new_settings['general']['role_based_filter']['include_roles']                               = isset( $_POST['general']['role_based_filter']['include_roles'] ) ? map_deep( $_POST['general']['role_based_filter']['include_roles'], 'sanitize_text_field' ) : array();
    867         $new_settings['general']['role_based_filter']['exclude_roles']                               = isset( $_POST['general']['role_based_filter']['exclude_roles'] ) ? map_deep( $_POST['general']['role_based_filter']['exclude_roles'], 'sanitize_text_field' ) : array();
     865        // set empty values for premium settings on basic build
     866        $defaults = [
     867            'limit_button_on_certain_products' => [
     868                'enabled'                     => false,
     869                'select_all'                  => false,
     870                'include_products_by_category' => [],
     871                'include_products_by_name'     => [],
     872                'include_products_by_tag'      => [],
     873            ],
     874            'exclude_products' => [
     875                'enabled'     => false,
     876                'select_all'  => false,
     877                'by_category' => [],
     878                'by_name'     => [],
     879                'by_tag'      => [],
     880            ],
     881            'role_based_filter' => [
     882                'enabled'       => false,
     883                'include_roles' => [],
     884                'exclude_roles' => [],
     885            ],
     886        ];
     887
     888        $new_settings['general'] = $defaults;
    868889       
    869890        return $general_setting_options->merge( $new_settings );
     
    879900
    880901    }
     902    /**
     903    * Disables the custom discount logic.
     904    * It ensures that the product returns its original database price (regular or sale)
     905    * without the plugin's additional calculations being applied.
     906    */
     907    public static function remove_price_filters() {
     908        remove_filter( 'woocommerce_product_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     909        remove_filter( 'woocommerce_product_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     910        remove_filter( 'woocommerce_product_variation_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     911        remove_filter( 'woocommerce_product_variation_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     912    }
     913
     914    /**
     915    * Enables the custom discount logic.
     916    * Whenever WooCommerce asks for a product price, the 'elex_ppct_discount_product'
     917    * method will intercept it and apply the configured discount.
     918    */
     919    public static function add_price_filters() {
     920        add_filter( 'woocommerce_product_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     921        add_filter( 'woocommerce_product_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     922        add_filter( 'woocommerce_product_variation_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     923        add_filter( 'woocommerce_product_variation_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     924    }
    881925}
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/includes/class-ppct-init-handler.php

    r3039228 r3458839  
    3939    }
    4040
    41     public function form_settings_localize_script() {
    42        
    43         wp_localize_script(
    44             'elex_ppct_formsetting',
    45             'raq_formsetting_ajax_object',
    46             array(
    47                 'ajax_url' => admin_url( 'admin-ajax.php' ),
    48                 'nonce'    => wp_create_nonce( 'raq-formsetting-ajax-nonce' ),
    49             )
    50         );
    51     }
    52 
    5341    public function enqueue_scripts() {
    5442        global $plugin_page;
     
    5644        $include_page = array( 'elex_product_price_custom_text_and_discount', 'ppct-help_support', 'ppct-go-premium' );
    5745        if ( in_array( $page, $include_page ) ) {
    58 
    59             wp_enqueue_script( 'elex_ppct_formsetting', plugins_url( dirname( $this->plugin_basename ) . '/assets/js/components/form_settings.min.js' ), array( 'jquery', 'wp-element', 'wp-i18n' ), self::VERSION );
    60             self::form_settings_localize_script();
    6146
    6247            wp_enqueue_script( 'elex_ppct_select_2_js', plugins_url( dirname( $this->plugin_basename ) . '/assets/js/select2-min.js' ), array( 'jquery', 'underscore' ), self::VERSION, true );
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/includes/elex-ppct-woocmmerce-variation-settings.php

    r3019704 r3458839  
    165165    jQuery(function($){
    166166
    167         // All fields checkbox
    168         const elex_ppct_custom_fields_checkbox = jQuery('#elex_ppct_custom_fields_checkbox');
    169         elex_ppct_custom_fields_checkbox.click(function(){
    170             var value=jQuery(this).is(':checked');
    171             if(value === true ){
    172                 jQuery('#elex_ppct_display_fields').show();
     167        // The main "custom text and discount" enable/disable checkbox for product
     168        jQuery('#elex_ppct_custom_fields_checkbox').on('change', function() {
     169            jQuery('#elex_ppct_display_fields').toggle(this.checked);
     170        }).change();
     171
     172        // Prefix checkbox
     173        jQuery('#elex_ppct_custom_fields_prefix_checkbox').on('change', function() {
     174            jQuery('#elex_ppct_custom_fields_prefix').closest('p').toggle(this.checked);
     175        }).change();
     176       
     177        // Suffix checkbox
     178        jQuery('#elex_ppct_custom_fields_suffix_checkbox').on('change', function() {
     179            jQuery('.elex_ppct_custom_fields_suffix_field').closest('p').toggle(this.checked);
     180        }).change();
     181       
     182
     183        // Discount type checkbox
     184        jQuery('#elex_ppct_custom_fields_discount_type_checkbox').on('change', function() {
     185            jQuery('#elex_ppct_discount_type').closest('p').toggle(this.checked);
     186            jQuery('#elex_ppct_discount_amount').closest('p').toggle(this.checked);
     187        }).change();
     188
     189        // Discount type change
     190        jQuery("#elex_ppct_discount_type").on('change', function() {
     191            const selectedVal = jQuery(this).val();
     192            const $amountField = jQuery('#elex_ppct_discount_amount');
     193            if (selectedVal === 'percent') {
     194                $amountField.attr('max', 100);
     195                if ($amountField.val() > 100) {
     196                    $amountField.val(100);
     197                }
    173198            } else {
    174                 jQuery('#elex_ppct_display_fields').hide();
     199                $amountField.removeAttr('max');
    175200            }
    176         });
    177         if (elex_ppct_custom_fields_checkbox.is(":checked")) {
    178             jQuery('#elex_ppct_display_fields').show();
    179         } else {
    180             jQuery('#elex_ppct_display_fields').hide();
    181         }
    182 
    183         // Prefix checkbox
    184         const elex_ppct_custom_fields_prefix_checkbox = jQuery('#elex_ppct_custom_fields_prefix_checkbox');
    185         elex_ppct_custom_fields_prefix_checkbox.on('change', function() {
    186             if(this.checked) {
    187                 jQuery('#elex_ppct_custom_fields_prefix').closest('p').show();
    188             } else {
    189                 jQuery('#elex_ppct_custom_fields_prefix').closest('p').hide();
    190             }
    191         });
    192         if( elex_ppct_custom_fields_prefix_checkbox.is(':checked') ) {
    193             jQuery('#elex_ppct_custom_fields_prefix').closest('p').show();
    194         } else {
    195             jQuery('#elex_ppct_custom_fields_prefix').closest('p').hide();
    196         }
    197 
    198         // Suffix checkbox
    199         const elex_ppct_custom_fields_suffix_checkbox = jQuery('#elex_ppct_custom_fields_suffix_checkbox');
    200         elex_ppct_custom_fields_suffix_checkbox.on('change', function() {
    201             if(this.checked) {
    202                 jQuery('.elex_ppct_custom_fields_suffix_field ').show();
    203             } else {
    204                 jQuery('.elex_ppct_custom_fields_suffix_field ').hide();
    205             }
    206         });
    207         if ( elex_ppct_custom_fields_suffix_checkbox.is(':checked') ) {
    208             jQuery('.elex_ppct_custom_fields_suffix_field ').show();
    209         } else {
    210             jQuery('.elex_ppct_custom_fields_suffix_field ').hide();
    211         }
    212 
    213         // Discount type checkbox
    214         const elex_ppct_custom_fields_discount_type_checkbox = jQuery('#elex_ppct_custom_fields_discount_type_checkbox');
    215         elex_ppct_custom_fields_discount_type_checkbox.on('change', function() {
    216             if(this.checked) {
    217                 jQuery('#elex_ppct_discount_type').closest('p').show();
    218                 jQuery('#elex_ppct_discount_amount').closest('p').show();
    219             } else {
    220                 jQuery('#elex_ppct_discount_type').closest('p').hide();
    221                 jQuery('#elex_ppct_discount_amount').closest('p').hide();
    222             }
    223         });
    224         if ( elex_ppct_custom_fields_discount_type_checkbox.is(':checked') ) {
    225             jQuery('#elex_ppct_discount_type').closest('p').show();
    226             jQuery('#elex_ppct_discount_amount').closest('p').show();
    227         } else {
    228             jQuery('#elex_ppct_discount_type').closest('p').hide();
    229             jQuery('#elex_ppct_discount_amount').closest('p').hide();
    230         }
     201        }).change();
     202
    231203    });
    232204
     
    373345                jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    374346                jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    375                 jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true);
    376                 jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true);
    377                 jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true);
     347                jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true).prop('disabled', false);
     348                jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true).prop('disabled', false);
     349                jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true).prop('disabled', false);
    378350            } else {
    379351                jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
     
    381353                jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    382354                jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    383                 jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false);
    384                 jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false);
    385                 jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false);
     355                jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
     356                jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
     357                jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
    386358            }
    387359        });
     
    396368            jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    397369            jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
     370
     371            // in intial load if the main checkbox is not checked then disable the prefix, suffix and discount checkboxs.
     372            jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
     373            jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
     374            jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
    398375        }
     376
    399377
    400378        // Hide and Show prefix field
    401379        jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').on('change',function() {
    402             if(this.checked){
    403                 jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    404             } else {
    405                 jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    406             }
    407         });
    408         if( jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').is(':checked') ) {
    409             jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    410         } else {
    411             jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    412         }
     380            jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').toggle(this.checked);
     381        }).change();
    413382
    414383        // Hide and Show suffix field.
    415384        jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').on('change',function() {
    416             if(this.checked){
    417                 jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    418             } else {
    419                 jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    420             }
    421         });
    422         if( jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').is(':checked') ) {
    423             jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    424         } else {
    425             jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    426         }
     385            jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').toggle(this.checked);
     386        }).change();
    427387
    428388        // Hide and Show discount field.
    429389        jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').on('change',function() {
    430             if(this.checked){
    431                 jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    432                 jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').show();
     390            jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').toggle(this.checked);
     391            jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').toggle(this.checked);
     392        }).change();
     393
     394
     395        jQuery('#elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>').on('change',function() {
     396            const selectedVal = jQuery(this).val();
     397            const $amountField = jQuery('#elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>');
     398            if (selectedVal === 'percent') {
     399                $amountField.attr('max', 100);
     400                if ($amountField.val() > 100) {
     401                    $amountField.val(100);
     402                }
    433403            } else {
    434                 jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    435                 jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
     404                $amountField.removeAttr('max');
    436405            }
    437         });
    438         if ( jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').is(':checked') ) {
    439             jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    440             jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    441         } else {
    442             jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    443             jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    444         }
     406        }).change();
     407
    445408    </script>
    446409    <?php
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/readme.txt

    r3383764 r3458839  
    33Tags: before & after text, woocommerce discounts, woocommerce dynamic pricing
    44Requires at least: 3.0.1
    5 Tested up to: 6.8
    6 Stable tag: 4.1.8
     5Tested up to: 6.9
     6Stable tag: 4.1.9
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5959== Changelog ==
    6060
     61= 4.1.9 =
     62* Made compatible with WordPress 6.9
     63* Improvement and minor bug fixes
     64
    6165= 4.1.8 =
    6266* Made compatible with WooCommerce 10.0.0
     
    228232== Upgrade Notice ==
    229233
     234= 4.1.9 =
     235* Made compatible with WordPress 6.9
     236* Improvement and minor bug fixes
     237
    230238= 4.1.8 =
    231239* Made compatible with WooCommerce 10.0.0
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/vendor/autoload.php

    r3383764 r3458839  
    1515        }
    1616    }
    17     trigger_error(
    18         $err,
    19         E_USER_ERROR
    20     );
     17    throw new RuntimeException($err);
    2118}
    2219
    2320require_once __DIR__ . '/composer/autoload_real.php';
    2421
    25 return ComposerAutoloaderInitf128f85d13f4c7ceefc4a739c1c0ef0a::getLoader();
     22return ComposerAutoloaderInit82ab9e04a1db6ace9a9fec4ef697c5b2::getLoader();
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/vendor/composer/ClassLoader.php

    r3189599 r3458839  
    4343class ClassLoader
    4444{
    45     /** @var ?string */
     45    /** @var \Closure(string):void */
     46    private static $includeFile;
     47
     48    /** @var string|null */
    4649    private $vendorDir;
    4750
    4851    // PSR-4
    4952    /**
    50      * @var array[]
    51      * @psalm-var array<string, array<string, int>>
     53     * @var array<string, array<string, int>>
    5254     */
    5355    private $prefixLengthsPsr4 = array();
    5456    /**
    55      * @var array[]
    56      * @psalm-var array<string, array<int, string>>
     57     * @var array<string, list<string>>
    5758     */
    5859    private $prefixDirsPsr4 = array();
    5960    /**
    60      * @var array[]
    61      * @psalm-var array<string, string>
     61     * @var list<string>
    6262     */
    6363    private $fallbackDirsPsr4 = array();
     
    6565    // PSR-0
    6666    /**
    67      * @var array[]
    68      * @psalm-var array<string, array<string, string[]>>
     67     * List of PSR-0 prefixes
     68     *
     69     * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
     70     *
     71     * @var array<string, array<string, list<string>>>
    6972     */
    7073    private $prefixesPsr0 = array();
    7174    /**
    72      * @var array[]
    73      * @psalm-var array<string, string>
     75     * @var list<string>
    7476     */
    7577    private $fallbackDirsPsr0 = array();
     
    7981
    8082    /**
    81      * @var string[]
    82      * @psalm-var array<string, string>
     83     * @var array<string, string>
    8384     */
    8485    private $classMap = array();
     
    8889
    8990    /**
    90      * @var bool[]
    91      * @psalm-var array<string, bool>
     91     * @var array<string, bool>
    9292     */
    9393    private $missingClasses = array();
    9494
    95     /** @var ?string */
     95    /** @var string|null */
    9696    private $apcuPrefix;
    9797
    9898    /**
    99      * @var self[]
     99     * @var array<string, self>
    100100     */
    101101    private static $registeredLoaders = array();
    102102
    103103    /**
    104      * @param ?string $vendorDir
     104     * @param string|null $vendorDir
    105105     */
    106106    public function __construct($vendorDir = null)
    107107    {
    108108        $this->vendorDir = $vendorDir;
    109     }
    110 
    111     /**
    112      * @return string[]
     109        self::initializeIncludeClosure();
     110    }
     111
     112    /**
     113     * @return array<string, list<string>>
    113114     */
    114115    public function getPrefixes()
     
    122123
    123124    /**
    124      * @return array[]
    125      * @psalm-return array<string, array<int, string>>
     125     * @return array<string, list<string>>
    126126     */
    127127    public function getPrefixesPsr4()
     
    131131
    132132    /**
    133      * @return array[]
    134      * @psalm-return array<string, string>
     133     * @return list<string>
    135134     */
    136135    public function getFallbackDirs()
     
    140139
    141140    /**
    142      * @return array[]
    143      * @psalm-return array<string, string>
     141     * @return list<string>
    144142     */
    145143    public function getFallbackDirsPsr4()
     
    149147
    150148    /**
    151      * @return string[] Array of classname => path
    152      * @psalm-return array<string, string>
     149     * @return array<string, string> Array of classname => path
    153150     */
    154151    public function getClassMap()
     
    158155
    159156    /**
    160      * @param string[] $classMap Class to filename map
    161      * @psalm-param array<string, string> $classMap
     157     * @param array<string, string> $classMap Class to filename map
    162158     *
    163159     * @return void
     
    176172     * appending or prepending to the ones previously set for this prefix.
    177173     *
    178      * @param string          $prefix  The prefix
    179      * @param string[]|string $paths   The PSR-0 root directories
    180      * @param bool            $prepend Whether to prepend the directories
     174     * @param string              $prefix  The prefix
     175     * @param list<string>|string $paths   The PSR-0 root directories
     176     * @param bool                $prepend Whether to prepend the directories
    181177     *
    182178     * @return void
     
    184180    public function add($prefix, $paths, $prepend = false)
    185181    {
     182        $paths = (array) $paths;
    186183        if (!$prefix) {
    187184            if ($prepend) {
    188185                $this->fallbackDirsPsr0 = array_merge(
    189                     (array) $paths,
     186                    $paths,
    190187                    $this->fallbackDirsPsr0
    191188                );
     
    193190                $this->fallbackDirsPsr0 = array_merge(
    194191                    $this->fallbackDirsPsr0,
    195                     (array) $paths
     192                    $paths
    196193                );
    197194            }
     
    202199        $first = $prefix[0];
    203200        if (!isset($this->prefixesPsr0[$first][$prefix])) {
    204             $this->prefixesPsr0[$first][$prefix] = (array) $paths;
     201            $this->prefixesPsr0[$first][$prefix] = $paths;
    205202
    206203            return;
     
    208205        if ($prepend) {
    209206            $this->prefixesPsr0[$first][$prefix] = array_merge(
    210                 (array) $paths,
     207                $paths,
    211208                $this->prefixesPsr0[$first][$prefix]
    212209            );
     
    214211            $this->prefixesPsr0[$first][$prefix] = array_merge(
    215212                $this->prefixesPsr0[$first][$prefix],
    216                 (array) $paths
     213                $paths
    217214            );
    218215        }
     
    223220     * appending or prepending to the ones previously set for this namespace.
    224221     *
    225      * @param string          $prefix  The prefix/namespace, with trailing '\\'
    226      * @param string[]|string $paths   The PSR-4 base directories
    227      * @param bool            $prepend Whether to prepend the directories
     222     * @param string              $prefix  The prefix/namespace, with trailing '\\'
     223     * @param list<string>|string $paths   The PSR-4 base directories
     224     * @param bool                $prepend Whether to prepend the directories
    228225     *
    229226     * @throws \InvalidArgumentException
     
    233230    public function addPsr4($prefix, $paths, $prepend = false)
    234231    {
     232        $paths = (array) $paths;
    235233        if (!$prefix) {
    236234            // Register directories for the root namespace.
    237235            if ($prepend) {
    238236                $this->fallbackDirsPsr4 = array_merge(
    239                     (array) $paths,
     237                    $paths,
    240238                    $this->fallbackDirsPsr4
    241239                );
     
    243241                $this->fallbackDirsPsr4 = array_merge(
    244242                    $this->fallbackDirsPsr4,
    245                     (array) $paths
     243                    $paths
    246244                );
    247245            }
     
    253251            }
    254252            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
    255             $this->prefixDirsPsr4[$prefix] = (array) $paths;
     253            $this->prefixDirsPsr4[$prefix] = $paths;
    256254        } elseif ($prepend) {
    257255            // Prepend directories for an already registered namespace.
    258256            $this->prefixDirsPsr4[$prefix] = array_merge(
    259                 (array) $paths,
     257                $paths,
    260258                $this->prefixDirsPsr4[$prefix]
    261259            );
     
    264262            $this->prefixDirsPsr4[$prefix] = array_merge(
    265263                $this->prefixDirsPsr4[$prefix],
    266                 (array) $paths
     264                $paths
    267265            );
    268266        }
     
    273271     * replacing any others previously set for this prefix.
    274272     *
    275      * @param string          $prefix The prefix
    276      * @param string[]|string $paths  The PSR-0 base directories
     273     * @param string              $prefix The prefix
     274     * @param list<string>|string $paths  The PSR-0 base directories
    277275     *
    278276     * @return void
     
    291289     * replacing any others previously set for this namespace.
    292290     *
    293      * @param string          $prefix The prefix/namespace, with trailing '\\'
    294      * @param string[]|string $paths  The PSR-4 base directories
     291     * @param string              $prefix The prefix/namespace, with trailing '\\'
     292     * @param list<string>|string $paths  The PSR-4 base directories
    295293     *
    296294     * @throws \InvalidArgumentException
     
    426424    {
    427425        if ($file = $this->findFile($class)) {
    428             includeFile($file);
     426            $includeFile = self::$includeFile;
     427            $includeFile($file);
    429428
    430429            return true;
     
    477476
    478477    /**
    479      * Returns the currently registered loaders indexed by their corresponding vendor directories.
    480      *
    481      * @return self[]
     478     * Returns the currently registered loaders keyed by their corresponding vendor directories.
     479     *
     480     * @return array<string, self>
    482481     */
    483482    public static function getRegisteredLoaders()
     
    556555        return false;
    557556    }
     557
     558    /**
     559     * @return void
     560     */
     561    private static function initializeIncludeClosure()
     562    {
     563        if (self::$includeFile !== null) {
     564            return;
     565        }
     566
     567        /**
     568         * Scope isolated include.
     569         *
     570         * Prevents access to $this/self from included files.
     571         *
     572         * @param  string $file
     573         * @return void
     574         */
     575        self::$includeFile = \Closure::bind(static function($file) {
     576            include $file;
     577        }, null, null);
     578    }
    558579}
    559 
    560 /**
    561  * Scope isolated include.
    562  *
    563  * Prevents access to $this/self from included files.
    564  *
    565  * @param  string $file
    566  * @return void
    567  * @private
    568  */
    569 function includeFile($file)
    570 {
    571     include $file;
    572 }
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/vendor/composer/InstalledVersions.php

    r3189599 r3458839  
    2828{
    2929    /**
     30     * @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
     31     * @internal
     32     */
     33    private static $selfDir = null;
     34
     35    /**
    3036     * @var mixed[]|null
    3137     * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
    3238     */
    3339    private static $installed;
     40
     41    /**
     42     * @var bool
     43     */
     44    private static $installedIsLocalDir;
    3445
    3546    /**
     
    99110        foreach (self::getInstalled() as $installed) {
    100111            if (isset($installed['versions'][$packageName])) {
    101                 return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
     112                return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
    102113            }
    103114        }
     
    120131    public static function satisfies(VersionParser $parser, $packageName, $constraint)
    121132    {
    122         $constraint = $parser->parseConstraints($constraint);
     133        $constraint = $parser->parseConstraints((string) $constraint);
    123134        $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
    124135
     
    310321        self::$installed = $data;
    311322        self::$installedByVendor = array();
     323
     324        // when using reload, we disable the duplicate protection to ensure that self::$installed data is
     325        // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
     326        // so we have to assume it does not, and that may result in duplicate data being returned when listing
     327        // all installed packages for example
     328        self::$installedIsLocalDir = false;
     329    }
     330
     331    /**
     332     * @return string
     333     */
     334    private static function getSelfDir()
     335    {
     336        if (self::$selfDir === null) {
     337            self::$selfDir = strtr(__DIR__, '\\', '/');
     338        }
     339
     340        return self::$selfDir;
    312341    }
    313342
     
    323352
    324353        $installed = array();
     354        $copiedLocalDir = false;
    325355
    326356        if (self::$canGetVendors) {
     357            $selfDir = self::getSelfDir();
    327358            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
     359                $vendorDir = strtr($vendorDir, '\\', '/');
    328360                if (isset(self::$installedByVendor[$vendorDir])) {
    329361                    $installed[] = self::$installedByVendor[$vendorDir];
    330362                } elseif (is_file($vendorDir.'/composer/installed.php')) {
    331                     $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
    332                     if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
    333                         self::$installed = $installed[count($installed) - 1];
     363                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     364                    $required = require $vendorDir.'/composer/installed.php';
     365                    self::$installedByVendor[$vendorDir] = $required;
     366                    $installed[] = $required;
     367                    if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
     368                        self::$installed = $required;
     369                        self::$installedIsLocalDir = true;
    334370                    }
     371                }
     372                if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
     373                    $copiedLocalDir = true;
    335374                }
    336375            }
     
    341380            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
    342381            if (substr(__DIR__, -8, 1) !== 'C') {
    343                 self::$installed = require __DIR__ . '/installed.php';
     382                /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     383                $required = require __DIR__ . '/installed.php';
     384                self::$installed = $required;
    344385            } else {
    345386                self::$installed = array();
    346387            }
    347388        }
    348         $installed[] = self::$installed;
     389
     390        if (self::$installed !== array() && !$copiedLocalDir) {
     391            $installed[] = self::$installed;
     392        }
    349393
    350394        return $installed;
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/vendor/composer/autoload_real.php

    r3383764 r3458839  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitf128f85d13f4c7ceefc4a739c1c0ef0a
     5class ComposerAutoloaderInit82ab9e04a1db6ace9a9fec4ef697c5b2
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInitf128f85d13f4c7ceefc4a739c1c0ef0a', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInit82ab9e04a1db6ace9a9fec4ef697c5b2', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderInitf128f85d13f4c7ceefc4a739c1c0ef0a', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInit82ab9e04a1db6ace9a9fec4ef697c5b2', 'loadClassLoader'));
    2828
    2929        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a::getInitializer($loader));
     30        call_user_func(\Composer\Autoload\ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2::getInitializer($loader));
    3131
    3232        $loader->register(true);
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/vendor/composer/autoload_static.php

    r3383764 r3458839  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a
     7class ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2
    88{
    99    public static $prefixLengthsPsr4 = array (
    10         'E' => 
     10        'E' =>
    1111        array (
    1212            'ELEX\\PPCT\\' => 10,
     
    1515
    1616    public static $prefixDirsPsr4 = array (
    17         'ELEX\\PPCT\\' => 
     17        'ELEX\\PPCT\\' =>
    1818        array (
    1919            0 => __DIR__ . '/../..' . '/includes',
     
    2828    {
    2929        return \Closure::bind(function () use ($loader) {
    30             $loader->prefixLengthsPsr4 = ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a::$prefixLengthsPsr4;
    31             $loader->prefixDirsPsr4 = ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a::$prefixDirsPsr4;
    32             $loader->classMap = ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a::$classMap;
     30            $loader->prefixLengthsPsr4 = ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2::$prefixLengthsPsr4;
     31            $loader->prefixDirsPsr4 = ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2::$prefixDirsPsr4;
     32            $loader->classMap = ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2::$classMap;
    3333
    3434        }, null, ClassLoader::class);
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/tags/4.1.9/vendor/composer/installed.php

    r3383764 r3458839  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => 'cbcc4feb128503adb599b9db9b878f1662b629cd',
     6        'reference' => 'caf2aa1024cb5a885ff23a3a42cc8e520e3e9f5e',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-master',
    1515            'version' => 'dev-master',
    16             'reference' => 'cbcc4feb128503adb599b9db9b878f1662b629cd',
     16            'reference' => 'caf2aa1024cb5a885ff23a3a42cc8e520e3e9f5e',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/assets/js/req_script.js

    r3019704 r3458839  
    2323    jQuery(function(){
    2424
    25         if (jQuery('#elex_ppct_discount_type').val() === 'no-discount') {
    26             jQuery('#elex_ppct_discount_amount').closest('tr').addClass('d-none');
    27         }
    28 
    2925        // On change event of the discount type dropdown
    3026        jQuery('#elex_ppct_discount_type').change(function() {
    31             if (jQuery(this).val() === 'no-discount') {
     27            const selectedVal = jQuery(this).val();
     28            const $amountField = jQuery('#elex_ppct_discount_amount');
     29            if (selectedVal === 'no-discount') {
    3230                // If "No Discount" is selected, hide the discount value field
    33                 jQuery('#elex_ppct_discount_amount').closest('tr').addClass('d-none');
     31                $amountField.closest('tr').addClass('d-none');
    3432            } else {
    3533                // If any other option is selected, show the discount value field
    36                 jQuery('#elex_ppct_discount_amount').closest('tr').removeClass('d-none');
    37             }
    38         });
     34                $amountField.closest('tr').removeClass('d-none');
     35                if (selectedVal === 'percent') {
     36                    $amountField.attr('max', 100);
     37                    if ($amountField.val() > 100) {
     38                        $amountField.val(100);
     39                    }
     40                } else {
     41                    $amountField.removeAttr('max');
     42                }
     43            }
     44        }).trigger('change');
    3945
    4046        //include products filter
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/assets/js/settings.js

    r3019704 r3458839  
    481481
    482482jQuery('.general_setting_save_chages').click(function(){
    483     if( jQuery('#exclude_product_enabled').prop('checked') ) {
    484          if(jQuery('.exclude_prod_by_cat').select2('data').length === 0 &&
    485         jQuery('.exclude_prod_by_name').select2('data').length === 0 &&
    486         jQuery('.exclude_prod_by_tag').select2('data').length === 0 ){
    487             alert("Choose any options for exclude category or tag or name");
     483    // while percentage discount is enabled discount percentage should be between 0 to 100
     484    if (jQuery('#elex_ppct_discount_type').val() === 'percent') {
     485        const discount_value = jQuery('#elex_ppct_discount_amount').val();
     486        if (discount_value < 0 || discount_value > 100) {
     487            alert("Enter valid discount percentage");
    488488            return false;
    489489        }
    490        
    491     }
    492     if( jQuery('#limit_product_is_enabled').prop('checked') ) {
    493         if(jQuery('.include_prod_by_cat').select2('data').length === 0 &&
    494        jQuery('.include_prod_by_name').select2('data').length === 0 &&
    495        jQuery('.include_prod_by_tag').select2('data').length === 0 ){
    496            alert("Choose any options for include category or tag or name");
    497            return false;
    498        }
    499        
    500    }
    501    
    502 
    503    if( jQuery('#role_based_enabled').prop('checked') ) {
    504     if(jQuery('.include_roles').select2('data').length === 0 &&
    505    jQuery('.exclude_roles').select2('data').length === 0 ){
    506        alert("Choose any options for user role.");
    507        return false;
    508    }
    509    
    510 }
    511 
    512 if( jQuery('#hide_add_cart_exclude').prop('checked') ) {
    513     if(jQuery('.hidecart_exclude_prod_by_cat').select2('data').length === 0 &&
    514    jQuery('.hidecart_exclude_prod_by_name').select2('data').length === 0 &&
    515    jQuery('.hidecart_exclude_prod_by_tag').select2('data').length === 0 ){
    516        alert("Choose any options for exclude category or tag or name");
    517        return false;
    518    }
    519  
    520 }
    521 
    522 
     490    }
    523491});
    524492jQuery('.hidecart_setting_save_chages').click(function(){
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/elex-woocommerce-product-price-custom-text-discount.php

    r3383764 r3458839  
    44Plugin URI: https://elextensions.com/plugin
    55Description: The plugin simplifies the task to add a text before and after the product price both globally and individually.It also allows you to apply a quick discount for your products.
    6 Version: 4.1.8
     6Version: 4.1.9
    77WC requires at least: 2.6.0
    88WC tested up to: 10.0.0
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/includes/SettingsController.php

    r3298807 r3458839  
    154154    // to get the base price of the product.
    155155    public static function elex_ppct_base_price( $product ) {
    156     remove_filter( 'woocommerce_product_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    157    remove_filter( 'woocommerce_product_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    158 
    159    remove_filter( 'woocommerce_product_variation_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    160    remove_filter( 'woocommerce_product_variation_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    161 
    162    $base_price = $product->get_regular_price();
    163    // for simple product price.
    164    add_filter( 'woocommerce_product_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    165    add_filter( 'woocommerce_product_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    166 
    167    // for variable product each variation price.
    168    add_filter( 'woocommerce_product_variation_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    169    add_filter( 'woocommerce_product_variation_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
    170 
    171    return $base_price;
     156        // remove the price filters to get the base price
     157        self::remove_price_filters();
     158
     159        // get the base price
     160        $base_price = $product->get_regular_price();
     161
     162        // add the price filters
     163        self::add_price_filters();
     164
     165        return $base_price;
    172166    }
    173167
     
    415409        if ( 'amount' === $type && is_numeric( $price ) ) {
    416410            $price = ( $price - ( ( float ) $discount ) );
     411            if ( $price < 0 ) {
     412                $price = 0;
     413            }
    417414        }
    418415        if ( 'percent' === $type && is_numeric( $price ) ) {
    419416            $price = ( $price - ( $price * ( ( float ) $discount / 100 ) ) );
     417            if ( $price < 0 ) {
     418                $price = 0;
     419            }
    420420        }
    421421    return $price;
     
    430430            $product_id = $product->get_id();
    431431        }
    432        
    433432        $product_info = wc_get_product( $product_id );
     433       
     434        // Prevent Recursion: Remove filters before querying product data
     435        self::remove_price_filters();
     436
     437        //fetch product data
     438        $is_on_sale = $product->is_on_sale();
     439       
     440        // Restore filters immediately
     441        self::add_price_filters();
     442        $current_hook = current_filter();
     443       
     444        // while applying this plugin's discount, no need to change/apply discount on regular price if product is on sale,
     445        if ( strpos( $current_hook, 'regular_price' ) !== false && $is_on_sale ) {
     446            return $price;
     447        }
     448
    434449        $custom_check_enable = 'no';
    435450        $custom_discount_checkbox = 'no';
    436 
    437451        if ( is_object( $product_info ) && method_exists( $product_info, 'get_meta' ) ) {
    438452            $custom_check_enable = $product_info->get_meta( 'elex_ppct_custom_fields_checkbox' ) ? $product_info->get_meta( 'elex_ppct_custom_fields_checkbox' ) : 'no';
    439453            $custom_discount_checkbox = $product_info->get_meta( 'elex_ppct_custom_fields_discount_type_checkbox' ) ? $product_info->get_meta( 'elex_ppct_custom_fields_discount_type_checkbox' ) : 'no';
    440454        }
    441        
    442 
    443         $check_enable             = get_option( 'elex_ppct_check_field' );
     455        $check_enable = get_option( 'elex_ppct_check_field' );
    444456
    445457        if ( ! empty( $variation_id ) ) {
     
    851863        $new_settings['elex_ppct_check_field']                                                       = isset( $_POST['elex_ppct_check_field'] ) ? true : false;
    852864
    853         $new_settings['general']['limit_button_on_certain_products']['enabled']                      = isset( $_POST['general']['limit_button_on_certain_products']['enabled'] ) ? true : false;
    854         $new_settings['general']['limit_button_on_certain_products']['select_all']                   = isset( $_POST['general']['limit_button_on_certain_products']['select_all'] ) ? true : false;
    855         $new_settings['general']['limit_button_on_certain_products']['include_products_by_category'] = isset( $_POST['general']['limit_button_on_certain_products']['include_products_by_category'] ) ? map_deep( $_POST['general']['limit_button_on_certain_products']['include_products_by_category'], 'sanitize_text_field' ) : array();
    856         $new_settings['general']['limit_button_on_certain_products']['include_products_by_name']     = isset( $_POST['general']['limit_button_on_certain_products']['include_products_by_name'] ) ? map_deep( $_POST['general']['limit_button_on_certain_products']['include_products_by_name'], 'sanitize_text_field' ) : array();
    857         $new_settings['general']['limit_button_on_certain_products']['include_products_by_tag']      = isset( $_POST['general']['limit_button_on_certain_products']['include_products_by_tag'] ) ? map_deep( $_POST['general']['limit_button_on_certain_products']['include_products_by_tag'], 'sanitize_text_field' ) : array();
    858        
    859         $new_settings['general']['exclude_products']['enabled']                                      = isset( $_POST['general']['exclude_products']['enabled'] ) ? true : false;
    860         $new_settings['general']['exclude_products']['select_all']                                   = isset( $_POST['general']['exclude_products']['select_all'] ) ? true : false;
    861         $new_settings['general']['exclude_products']['by_category']                                  = isset( $_POST['general']['exclude_products']['by_category'] ) ? map_deep( $_POST['general']['exclude_products']['by_category'], 'sanitize_text_field' ) : array();
    862         $new_settings['general']['exclude_products']['by_name']                                      = isset( $_POST['general']['exclude_products']['by_name'] ) ? map_deep( $_POST['general']['exclude_products']['by_name'], 'sanitize_text_field' ) : array();
    863         $new_settings['general']['exclude_products']['by_tag']                                       = isset( $_POST['general']['exclude_products']['by_tag'] ) ? map_deep( $_POST['general']['exclude_products']['by_tag'], 'sanitize_text_field' ) : array();
    864        
    865         $new_settings['general']['role_based_filter']['enabled']                                     = isset( $_POST['general']['role_based_filter']['enabled'] ) ? true : false;
    866         $new_settings['general']['role_based_filter']['include_roles']                               = isset( $_POST['general']['role_based_filter']['include_roles'] ) ? map_deep( $_POST['general']['role_based_filter']['include_roles'], 'sanitize_text_field' ) : array();
    867         $new_settings['general']['role_based_filter']['exclude_roles']                               = isset( $_POST['general']['role_based_filter']['exclude_roles'] ) ? map_deep( $_POST['general']['role_based_filter']['exclude_roles'], 'sanitize_text_field' ) : array();
     865        // set empty values for premium settings on basic build
     866        $defaults = [
     867            'limit_button_on_certain_products' => [
     868                'enabled'                     => false,
     869                'select_all'                  => false,
     870                'include_products_by_category' => [],
     871                'include_products_by_name'     => [],
     872                'include_products_by_tag'      => [],
     873            ],
     874            'exclude_products' => [
     875                'enabled'     => false,
     876                'select_all'  => false,
     877                'by_category' => [],
     878                'by_name'     => [],
     879                'by_tag'      => [],
     880            ],
     881            'role_based_filter' => [
     882                'enabled'       => false,
     883                'include_roles' => [],
     884                'exclude_roles' => [],
     885            ],
     886        ];
     887
     888        $new_settings['general'] = $defaults;
    868889       
    869890        return $general_setting_options->merge( $new_settings );
     
    879900
    880901    }
     902    /**
     903    * Disables the custom discount logic.
     904    * It ensures that the product returns its original database price (regular or sale)
     905    * without the plugin's additional calculations being applied.
     906    */
     907    public static function remove_price_filters() {
     908        remove_filter( 'woocommerce_product_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     909        remove_filter( 'woocommerce_product_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     910        remove_filter( 'woocommerce_product_variation_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     911        remove_filter( 'woocommerce_product_variation_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     912    }
     913
     914    /**
     915    * Enables the custom discount logic.
     916    * Whenever WooCommerce asks for a product price, the 'elex_ppct_discount_product'
     917    * method will intercept it and apply the configured discount.
     918    */
     919    public static function add_price_filters() {
     920        add_filter( 'woocommerce_product_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     921        add_filter( 'woocommerce_product_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     922        add_filter( 'woocommerce_product_variation_get_regular_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     923        add_filter( 'woocommerce_product_variation_get_price', array( self::class, 'elex_ppct_discount_product' ), 8, 2 );
     924    }
    881925}
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/includes/class-ppct-init-handler.php

    r3039228 r3458839  
    3939    }
    4040
    41     public function form_settings_localize_script() {
    42        
    43         wp_localize_script(
    44             'elex_ppct_formsetting',
    45             'raq_formsetting_ajax_object',
    46             array(
    47                 'ajax_url' => admin_url( 'admin-ajax.php' ),
    48                 'nonce'    => wp_create_nonce( 'raq-formsetting-ajax-nonce' ),
    49             )
    50         );
    51     }
    52 
    5341    public function enqueue_scripts() {
    5442        global $plugin_page;
     
    5644        $include_page = array( 'elex_product_price_custom_text_and_discount', 'ppct-help_support', 'ppct-go-premium' );
    5745        if ( in_array( $page, $include_page ) ) {
    58 
    59             wp_enqueue_script( 'elex_ppct_formsetting', plugins_url( dirname( $this->plugin_basename ) . '/assets/js/components/form_settings.min.js' ), array( 'jquery', 'wp-element', 'wp-i18n' ), self::VERSION );
    60             self::form_settings_localize_script();
    6146
    6247            wp_enqueue_script( 'elex_ppct_select_2_js', plugins_url( dirname( $this->plugin_basename ) . '/assets/js/select2-min.js' ), array( 'jquery', 'underscore' ), self::VERSION, true );
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/includes/elex-ppct-woocmmerce-variation-settings.php

    r3019704 r3458839  
    165165    jQuery(function($){
    166166
    167         // All fields checkbox
    168         const elex_ppct_custom_fields_checkbox = jQuery('#elex_ppct_custom_fields_checkbox');
    169         elex_ppct_custom_fields_checkbox.click(function(){
    170             var value=jQuery(this).is(':checked');
    171             if(value === true ){
    172                 jQuery('#elex_ppct_display_fields').show();
     167        // The main "custom text and discount" enable/disable checkbox for product
     168        jQuery('#elex_ppct_custom_fields_checkbox').on('change', function() {
     169            jQuery('#elex_ppct_display_fields').toggle(this.checked);
     170        }).change();
     171
     172        // Prefix checkbox
     173        jQuery('#elex_ppct_custom_fields_prefix_checkbox').on('change', function() {
     174            jQuery('#elex_ppct_custom_fields_prefix').closest('p').toggle(this.checked);
     175        }).change();
     176       
     177        // Suffix checkbox
     178        jQuery('#elex_ppct_custom_fields_suffix_checkbox').on('change', function() {
     179            jQuery('.elex_ppct_custom_fields_suffix_field').closest('p').toggle(this.checked);
     180        }).change();
     181       
     182
     183        // Discount type checkbox
     184        jQuery('#elex_ppct_custom_fields_discount_type_checkbox').on('change', function() {
     185            jQuery('#elex_ppct_discount_type').closest('p').toggle(this.checked);
     186            jQuery('#elex_ppct_discount_amount').closest('p').toggle(this.checked);
     187        }).change();
     188
     189        // Discount type change
     190        jQuery("#elex_ppct_discount_type").on('change', function() {
     191            const selectedVal = jQuery(this).val();
     192            const $amountField = jQuery('#elex_ppct_discount_amount');
     193            if (selectedVal === 'percent') {
     194                $amountField.attr('max', 100);
     195                if ($amountField.val() > 100) {
     196                    $amountField.val(100);
     197                }
    173198            } else {
    174                 jQuery('#elex_ppct_display_fields').hide();
     199                $amountField.removeAttr('max');
    175200            }
    176         });
    177         if (elex_ppct_custom_fields_checkbox.is(":checked")) {
    178             jQuery('#elex_ppct_display_fields').show();
    179         } else {
    180             jQuery('#elex_ppct_display_fields').hide();
    181         }
    182 
    183         // Prefix checkbox
    184         const elex_ppct_custom_fields_prefix_checkbox = jQuery('#elex_ppct_custom_fields_prefix_checkbox');
    185         elex_ppct_custom_fields_prefix_checkbox.on('change', function() {
    186             if(this.checked) {
    187                 jQuery('#elex_ppct_custom_fields_prefix').closest('p').show();
    188             } else {
    189                 jQuery('#elex_ppct_custom_fields_prefix').closest('p').hide();
    190             }
    191         });
    192         if( elex_ppct_custom_fields_prefix_checkbox.is(':checked') ) {
    193             jQuery('#elex_ppct_custom_fields_prefix').closest('p').show();
    194         } else {
    195             jQuery('#elex_ppct_custom_fields_prefix').closest('p').hide();
    196         }
    197 
    198         // Suffix checkbox
    199         const elex_ppct_custom_fields_suffix_checkbox = jQuery('#elex_ppct_custom_fields_suffix_checkbox');
    200         elex_ppct_custom_fields_suffix_checkbox.on('change', function() {
    201             if(this.checked) {
    202                 jQuery('.elex_ppct_custom_fields_suffix_field ').show();
    203             } else {
    204                 jQuery('.elex_ppct_custom_fields_suffix_field ').hide();
    205             }
    206         });
    207         if ( elex_ppct_custom_fields_suffix_checkbox.is(':checked') ) {
    208             jQuery('.elex_ppct_custom_fields_suffix_field ').show();
    209         } else {
    210             jQuery('.elex_ppct_custom_fields_suffix_field ').hide();
    211         }
    212 
    213         // Discount type checkbox
    214         const elex_ppct_custom_fields_discount_type_checkbox = jQuery('#elex_ppct_custom_fields_discount_type_checkbox');
    215         elex_ppct_custom_fields_discount_type_checkbox.on('change', function() {
    216             if(this.checked) {
    217                 jQuery('#elex_ppct_discount_type').closest('p').show();
    218                 jQuery('#elex_ppct_discount_amount').closest('p').show();
    219             } else {
    220                 jQuery('#elex_ppct_discount_type').closest('p').hide();
    221                 jQuery('#elex_ppct_discount_amount').closest('p').hide();
    222             }
    223         });
    224         if ( elex_ppct_custom_fields_discount_type_checkbox.is(':checked') ) {
    225             jQuery('#elex_ppct_discount_type').closest('p').show();
    226             jQuery('#elex_ppct_discount_amount').closest('p').show();
    227         } else {
    228             jQuery('#elex_ppct_discount_type').closest('p').hide();
    229             jQuery('#elex_ppct_discount_amount').closest('p').hide();
    230         }
     201        }).change();
     202
    231203    });
    232204
     
    373345                jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    374346                jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    375                 jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true);
    376                 jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true);
    377                 jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true);
     347                jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true).prop('disabled', false);
     348                jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true).prop('disabled', false);
     349                jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', true).prop('disabled', false);
    378350            } else {
    379351                jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
     
    381353                jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    382354                jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    383                 jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false);
    384                 jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false);
    385                 jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false);
     355                jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
     356                jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
     357                jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
    386358            }
    387359        });
     
    396368            jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    397369            jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
     370
     371            // in intial load if the main checkbox is not checked then disable the prefix, suffix and discount checkboxs.
     372            jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
     373            jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
     374            jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').prop('checked', false).prop('disabled', true);
    398375        }
     376
    399377
    400378        // Hide and Show prefix field
    401379        jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').on('change',function() {
    402             if(this.checked){
    403                 jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    404             } else {
    405                 jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    406             }
    407         });
    408         if( jQuery('#elex_ppct_variation_use_prefix_id_<?php esc_attr_e( $variation->ID ); ?>').is(':checked') ) {
    409             jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    410         } else {
    411             jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    412         }
     380            jQuery('.elex_ppct_variation_add_prefix_<?php esc_attr_e( $variation->ID ); ?>_field').toggle(this.checked);
     381        }).change();
    413382
    414383        // Hide and Show suffix field.
    415384        jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').on('change',function() {
    416             if(this.checked){
    417                 jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    418             } else {
    419                 jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    420             }
    421         });
    422         if( jQuery('#elex_ppct_variation_use_suffix_id_<?php esc_attr_e( $variation->ID ); ?>').is(':checked') ) {
    423             jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    424         } else {
    425             jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    426         }
     385            jQuery('.elex_ppct_variation_add_suffix_<?php esc_attr_e( $variation->ID ); ?>_field').toggle(this.checked);
     386        }).change();
    427387
    428388        // Hide and Show discount field.
    429389        jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').on('change',function() {
    430             if(this.checked){
    431                 jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    432                 jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').show();
     390            jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').toggle(this.checked);
     391            jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').toggle(this.checked);
     392        }).change();
     393
     394
     395        jQuery('#elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>').on('change',function() {
     396            const selectedVal = jQuery(this).val();
     397            const $amountField = jQuery('#elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>');
     398            if (selectedVal === 'percent') {
     399                $amountField.attr('max', 100);
     400                if ($amountField.val() > 100) {
     401                    $amountField.val(100);
     402                }
    433403            } else {
    434                 jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    435                 jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
     404                $amountField.removeAttr('max');
    436405            }
    437         });
    438         if ( jQuery('#elex_ppct_variation_use_discount_id_<?php esc_attr_e( $variation->ID ); ?>').is(':checked') ) {
    439             jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    440             jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').show();
    441         } else {
    442             jQuery('.elex_ppct_discount_type_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    443             jQuery('.elex_ppct_discount_amount_<?php esc_attr_e( $variation->ID ); ?>_field').hide();
    444         }
     406        }).change();
     407
    445408    </script>
    446409    <?php
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/readme.txt

    r3383764 r3458839  
    33Tags: before & after text, woocommerce discounts, woocommerce dynamic pricing
    44Requires at least: 3.0.1
    5 Tested up to: 6.8
    6 Stable tag: 4.1.8
     5Tested up to: 6.9
     6Stable tag: 4.1.9
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5959== Changelog ==
    6060
     61= 4.1.9 =
     62* Made compatible with WordPress 6.9
     63* Improvement and minor bug fixes
     64
    6165= 4.1.8 =
    6266* Made compatible with WooCommerce 10.0.0
     
    228232== Upgrade Notice ==
    229233
     234= 4.1.9 =
     235* Made compatible with WordPress 6.9
     236* Improvement and minor bug fixes
     237
    230238= 4.1.8 =
    231239* Made compatible with WooCommerce 10.0.0
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/vendor/autoload.php

    r3383764 r3458839  
    1515        }
    1616    }
    17     trigger_error(
    18         $err,
    19         E_USER_ERROR
    20     );
     17    throw new RuntimeException($err);
    2118}
    2219
    2320require_once __DIR__ . '/composer/autoload_real.php';
    2421
    25 return ComposerAutoloaderInitf128f85d13f4c7ceefc4a739c1c0ef0a::getLoader();
     22return ComposerAutoloaderInit82ab9e04a1db6ace9a9fec4ef697c5b2::getLoader();
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/vendor/composer/ClassLoader.php

    r3189599 r3458839  
    4343class ClassLoader
    4444{
    45     /** @var ?string */
     45    /** @var \Closure(string):void */
     46    private static $includeFile;
     47
     48    /** @var string|null */
    4649    private $vendorDir;
    4750
    4851    // PSR-4
    4952    /**
    50      * @var array[]
    51      * @psalm-var array<string, array<string, int>>
     53     * @var array<string, array<string, int>>
    5254     */
    5355    private $prefixLengthsPsr4 = array();
    5456    /**
    55      * @var array[]
    56      * @psalm-var array<string, array<int, string>>
     57     * @var array<string, list<string>>
    5758     */
    5859    private $prefixDirsPsr4 = array();
    5960    /**
    60      * @var array[]
    61      * @psalm-var array<string, string>
     61     * @var list<string>
    6262     */
    6363    private $fallbackDirsPsr4 = array();
     
    6565    // PSR-0
    6666    /**
    67      * @var array[]
    68      * @psalm-var array<string, array<string, string[]>>
     67     * List of PSR-0 prefixes
     68     *
     69     * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
     70     *
     71     * @var array<string, array<string, list<string>>>
    6972     */
    7073    private $prefixesPsr0 = array();
    7174    /**
    72      * @var array[]
    73      * @psalm-var array<string, string>
     75     * @var list<string>
    7476     */
    7577    private $fallbackDirsPsr0 = array();
     
    7981
    8082    /**
    81      * @var string[]
    82      * @psalm-var array<string, string>
     83     * @var array<string, string>
    8384     */
    8485    private $classMap = array();
     
    8889
    8990    /**
    90      * @var bool[]
    91      * @psalm-var array<string, bool>
     91     * @var array<string, bool>
    9292     */
    9393    private $missingClasses = array();
    9494
    95     /** @var ?string */
     95    /** @var string|null */
    9696    private $apcuPrefix;
    9797
    9898    /**
    99      * @var self[]
     99     * @var array<string, self>
    100100     */
    101101    private static $registeredLoaders = array();
    102102
    103103    /**
    104      * @param ?string $vendorDir
     104     * @param string|null $vendorDir
    105105     */
    106106    public function __construct($vendorDir = null)
    107107    {
    108108        $this->vendorDir = $vendorDir;
    109     }
    110 
    111     /**
    112      * @return string[]
     109        self::initializeIncludeClosure();
     110    }
     111
     112    /**
     113     * @return array<string, list<string>>
    113114     */
    114115    public function getPrefixes()
     
    122123
    123124    /**
    124      * @return array[]
    125      * @psalm-return array<string, array<int, string>>
     125     * @return array<string, list<string>>
    126126     */
    127127    public function getPrefixesPsr4()
     
    131131
    132132    /**
    133      * @return array[]
    134      * @psalm-return array<string, string>
     133     * @return list<string>
    135134     */
    136135    public function getFallbackDirs()
     
    140139
    141140    /**
    142      * @return array[]
    143      * @psalm-return array<string, string>
     141     * @return list<string>
    144142     */
    145143    public function getFallbackDirsPsr4()
     
    149147
    150148    /**
    151      * @return string[] Array of classname => path
    152      * @psalm-return array<string, string>
     149     * @return array<string, string> Array of classname => path
    153150     */
    154151    public function getClassMap()
     
    158155
    159156    /**
    160      * @param string[] $classMap Class to filename map
    161      * @psalm-param array<string, string> $classMap
     157     * @param array<string, string> $classMap Class to filename map
    162158     *
    163159     * @return void
     
    176172     * appending or prepending to the ones previously set for this prefix.
    177173     *
    178      * @param string          $prefix  The prefix
    179      * @param string[]|string $paths   The PSR-0 root directories
    180      * @param bool            $prepend Whether to prepend the directories
     174     * @param string              $prefix  The prefix
     175     * @param list<string>|string $paths   The PSR-0 root directories
     176     * @param bool                $prepend Whether to prepend the directories
    181177     *
    182178     * @return void
     
    184180    public function add($prefix, $paths, $prepend = false)
    185181    {
     182        $paths = (array) $paths;
    186183        if (!$prefix) {
    187184            if ($prepend) {
    188185                $this->fallbackDirsPsr0 = array_merge(
    189                     (array) $paths,
     186                    $paths,
    190187                    $this->fallbackDirsPsr0
    191188                );
     
    193190                $this->fallbackDirsPsr0 = array_merge(
    194191                    $this->fallbackDirsPsr0,
    195                     (array) $paths
     192                    $paths
    196193                );
    197194            }
     
    202199        $first = $prefix[0];
    203200        if (!isset($this->prefixesPsr0[$first][$prefix])) {
    204             $this->prefixesPsr0[$first][$prefix] = (array) $paths;
     201            $this->prefixesPsr0[$first][$prefix] = $paths;
    205202
    206203            return;
     
    208205        if ($prepend) {
    209206            $this->prefixesPsr0[$first][$prefix] = array_merge(
    210                 (array) $paths,
     207                $paths,
    211208                $this->prefixesPsr0[$first][$prefix]
    212209            );
     
    214211            $this->prefixesPsr0[$first][$prefix] = array_merge(
    215212                $this->prefixesPsr0[$first][$prefix],
    216                 (array) $paths
     213                $paths
    217214            );
    218215        }
     
    223220     * appending or prepending to the ones previously set for this namespace.
    224221     *
    225      * @param string          $prefix  The prefix/namespace, with trailing '\\'
    226      * @param string[]|string $paths   The PSR-4 base directories
    227      * @param bool            $prepend Whether to prepend the directories
     222     * @param string              $prefix  The prefix/namespace, with trailing '\\'
     223     * @param list<string>|string $paths   The PSR-4 base directories
     224     * @param bool                $prepend Whether to prepend the directories
    228225     *
    229226     * @throws \InvalidArgumentException
     
    233230    public function addPsr4($prefix, $paths, $prepend = false)
    234231    {
     232        $paths = (array) $paths;
    235233        if (!$prefix) {
    236234            // Register directories for the root namespace.
    237235            if ($prepend) {
    238236                $this->fallbackDirsPsr4 = array_merge(
    239                     (array) $paths,
     237                    $paths,
    240238                    $this->fallbackDirsPsr4
    241239                );
     
    243241                $this->fallbackDirsPsr4 = array_merge(
    244242                    $this->fallbackDirsPsr4,
    245                     (array) $paths
     243                    $paths
    246244                );
    247245            }
     
    253251            }
    254252            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
    255             $this->prefixDirsPsr4[$prefix] = (array) $paths;
     253            $this->prefixDirsPsr4[$prefix] = $paths;
    256254        } elseif ($prepend) {
    257255            // Prepend directories for an already registered namespace.
    258256            $this->prefixDirsPsr4[$prefix] = array_merge(
    259                 (array) $paths,
     257                $paths,
    260258                $this->prefixDirsPsr4[$prefix]
    261259            );
     
    264262            $this->prefixDirsPsr4[$prefix] = array_merge(
    265263                $this->prefixDirsPsr4[$prefix],
    266                 (array) $paths
     264                $paths
    267265            );
    268266        }
     
    273271     * replacing any others previously set for this prefix.
    274272     *
    275      * @param string          $prefix The prefix
    276      * @param string[]|string $paths  The PSR-0 base directories
     273     * @param string              $prefix The prefix
     274     * @param list<string>|string $paths  The PSR-0 base directories
    277275     *
    278276     * @return void
     
    291289     * replacing any others previously set for this namespace.
    292290     *
    293      * @param string          $prefix The prefix/namespace, with trailing '\\'
    294      * @param string[]|string $paths  The PSR-4 base directories
     291     * @param string              $prefix The prefix/namespace, with trailing '\\'
     292     * @param list<string>|string $paths  The PSR-4 base directories
    295293     *
    296294     * @throws \InvalidArgumentException
     
    426424    {
    427425        if ($file = $this->findFile($class)) {
    428             includeFile($file);
     426            $includeFile = self::$includeFile;
     427            $includeFile($file);
    429428
    430429            return true;
     
    477476
    478477    /**
    479      * Returns the currently registered loaders indexed by their corresponding vendor directories.
    480      *
    481      * @return self[]
     478     * Returns the currently registered loaders keyed by their corresponding vendor directories.
     479     *
     480     * @return array<string, self>
    482481     */
    483482    public static function getRegisteredLoaders()
     
    556555        return false;
    557556    }
     557
     558    /**
     559     * @return void
     560     */
     561    private static function initializeIncludeClosure()
     562    {
     563        if (self::$includeFile !== null) {
     564            return;
     565        }
     566
     567        /**
     568         * Scope isolated include.
     569         *
     570         * Prevents access to $this/self from included files.
     571         *
     572         * @param  string $file
     573         * @return void
     574         */
     575        self::$includeFile = \Closure::bind(static function($file) {
     576            include $file;
     577        }, null, null);
     578    }
    558579}
    559 
    560 /**
    561  * Scope isolated include.
    562  *
    563  * Prevents access to $this/self from included files.
    564  *
    565  * @param  string $file
    566  * @return void
    567  * @private
    568  */
    569 function includeFile($file)
    570 {
    571     include $file;
    572 }
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/vendor/composer/InstalledVersions.php

    r3189599 r3458839  
    2828{
    2929    /**
     30     * @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
     31     * @internal
     32     */
     33    private static $selfDir = null;
     34
     35    /**
    3036     * @var mixed[]|null
    3137     * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
    3238     */
    3339    private static $installed;
     40
     41    /**
     42     * @var bool
     43     */
     44    private static $installedIsLocalDir;
    3445
    3546    /**
     
    99110        foreach (self::getInstalled() as $installed) {
    100111            if (isset($installed['versions'][$packageName])) {
    101                 return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
     112                return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
    102113            }
    103114        }
     
    120131    public static function satisfies(VersionParser $parser, $packageName, $constraint)
    121132    {
    122         $constraint = $parser->parseConstraints($constraint);
     133        $constraint = $parser->parseConstraints((string) $constraint);
    123134        $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
    124135
     
    310321        self::$installed = $data;
    311322        self::$installedByVendor = array();
     323
     324        // when using reload, we disable the duplicate protection to ensure that self::$installed data is
     325        // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
     326        // so we have to assume it does not, and that may result in duplicate data being returned when listing
     327        // all installed packages for example
     328        self::$installedIsLocalDir = false;
     329    }
     330
     331    /**
     332     * @return string
     333     */
     334    private static function getSelfDir()
     335    {
     336        if (self::$selfDir === null) {
     337            self::$selfDir = strtr(__DIR__, '\\', '/');
     338        }
     339
     340        return self::$selfDir;
    312341    }
    313342
     
    323352
    324353        $installed = array();
     354        $copiedLocalDir = false;
    325355
    326356        if (self::$canGetVendors) {
     357            $selfDir = self::getSelfDir();
    327358            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
     359                $vendorDir = strtr($vendorDir, '\\', '/');
    328360                if (isset(self::$installedByVendor[$vendorDir])) {
    329361                    $installed[] = self::$installedByVendor[$vendorDir];
    330362                } elseif (is_file($vendorDir.'/composer/installed.php')) {
    331                     $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
    332                     if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
    333                         self::$installed = $installed[count($installed) - 1];
     363                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     364                    $required = require $vendorDir.'/composer/installed.php';
     365                    self::$installedByVendor[$vendorDir] = $required;
     366                    $installed[] = $required;
     367                    if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
     368                        self::$installed = $required;
     369                        self::$installedIsLocalDir = true;
    334370                    }
     371                }
     372                if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
     373                    $copiedLocalDir = true;
    335374                }
    336375            }
     
    341380            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
    342381            if (substr(__DIR__, -8, 1) !== 'C') {
    343                 self::$installed = require __DIR__ . '/installed.php';
     382                /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     383                $required = require __DIR__ . '/installed.php';
     384                self::$installed = $required;
    344385            } else {
    345386                self::$installed = array();
    346387            }
    347388        }
    348         $installed[] = self::$installed;
     389
     390        if (self::$installed !== array() && !$copiedLocalDir) {
     391            $installed[] = self::$installed;
     392        }
    349393
    350394        return $installed;
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/vendor/composer/autoload_real.php

    r3383764 r3458839  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitf128f85d13f4c7ceefc4a739c1c0ef0a
     5class ComposerAutoloaderInit82ab9e04a1db6ace9a9fec4ef697c5b2
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInitf128f85d13f4c7ceefc4a739c1c0ef0a', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInit82ab9e04a1db6ace9a9fec4ef697c5b2', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderInitf128f85d13f4c7ceefc4a739c1c0ef0a', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInit82ab9e04a1db6ace9a9fec4ef697c5b2', 'loadClassLoader'));
    2828
    2929        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a::getInitializer($loader));
     30        call_user_func(\Composer\Autoload\ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2::getInitializer($loader));
    3131
    3232        $loader->register(true);
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/vendor/composer/autoload_static.php

    r3383764 r3458839  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a
     7class ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2
    88{
    99    public static $prefixLengthsPsr4 = array (
    10         'E' => 
     10        'E' =>
    1111        array (
    1212            'ELEX\\PPCT\\' => 10,
     
    1515
    1616    public static $prefixDirsPsr4 = array (
    17         'ELEX\\PPCT\\' => 
     17        'ELEX\\PPCT\\' =>
    1818        array (
    1919            0 => __DIR__ . '/../..' . '/includes',
     
    2828    {
    2929        return \Closure::bind(function () use ($loader) {
    30             $loader->prefixLengthsPsr4 = ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a::$prefixLengthsPsr4;
    31             $loader->prefixDirsPsr4 = ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a::$prefixDirsPsr4;
    32             $loader->classMap = ComposerStaticInitf128f85d13f4c7ceefc4a739c1c0ef0a::$classMap;
     30            $loader->prefixLengthsPsr4 = ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2::$prefixLengthsPsr4;
     31            $loader->prefixDirsPsr4 = ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2::$prefixDirsPsr4;
     32            $loader->classMap = ComposerStaticInit82ab9e04a1db6ace9a9fec4ef697c5b2::$classMap;
    3333
    3434        }, null, ClassLoader::class);
  • elex-product-price-custom-text-before-after-text-and-discount-for-woocommerce/trunk/vendor/composer/installed.php

    r3383764 r3458839  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => 'cbcc4feb128503adb599b9db9b878f1662b629cd',
     6        'reference' => 'caf2aa1024cb5a885ff23a3a42cc8e520e3e9f5e',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-master',
    1515            'version' => 'dev-master',
    16             'reference' => 'cbcc4feb128503adb599b9db9b878f1662b629cd',
     16            'reference' => 'caf2aa1024cb5a885ff23a3a42cc8e520e3e9f5e',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.