Plugin Directory

Changeset 3327241


Ignore:
Timestamp:
07/13/2025 11:04:58 PM (7 months ago)
Author:
fullstackhouse
Message:

tagging 1.8.0

Location:
wc-smart-cod
Files:
10 edited
6 copied

Legend:

Unmodified
Added
Removed
  • wc-smart-cod/tags/1.8.0/README.txt

    r3277209 r3327241  
    33Tags: WooCommerce, Cash on Delivery, COD, COD Extra Fee, Smart COD, WooCommerce COD, Multiple Fees
    44Requires at least: 3.0.1
    5 Tested up to: 6.8
    6 Stable tag: 1.7.3
     5Tested up to: 6.8.1
     6Stable tag: 1.8.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • wc-smart-cod/tags/1.8.0/admin/class-wc-smart-cod-admin.php

    r3277209 r3327241  
    5151    public $new_wc = false;
    5252
     53    private $restriction_settings = array();
     54
     55    private $fee_settings = array();
     56
     57    private $prepared_fields = array();
     58
     59    private $settings_manager = array();
     60
    5361    public function __construct() {
    5462
     
    5664        $this->plugin_name = 'wc-smart-cod';
    5765        $this->version = SMART_COD_VER;
     66       
     67        $this->settings_manager = (object)Wc_Smart_Cod::get_settings_manager();
    5868
    5969        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    6070        add_action( 'woocommerce_settings_api_form_fields_cod', array( $this, 'extend_cod' ) );
    6171        add_action( 'woocommerce_settings_api_sanitized_fields_cod', array( $this, 'clean_up_settings' ) );
     72        add_filter( 'experimental_woocommerce_admin_payment_reactify_render_sections', array( $this, 'woocommerce_smart_cod') );
    6273        add_action( 'woocommerce_delete_shipping_zone', array( $this, 'clean_up_gateway' ) );
    6374    }
     
    144155        echo '</h2>';
    145156        echo wp_kses_post( wpautop( $this->get_method_description() ) );
     157       
    146158        $template_data = array(
    147159            'promo_texts' => WC_Smart_Cod::$promo_texts,
     
    221233    }
    222234
     235    public function woocommerce_smart_cod($sections) {
     236        $cod = 'cod';
     237        return array_filter($sections, function($v) use ($cod) {
     238            return $v !== $cod;
     239        });
     240    }
     241
     242    public function get_field_value($key, $field, $post_data = array())
     243    {
     244        if ($this->has_prefix_in_array($key, $this->settings_manager->e)) {
     245            if (!in_array($key, haystack: $this->settings_manager->d)) {
     246                if (isset($this->settings[$key]) && $this->settings[$key] !== '') {
     247                    return $this->settings[$key];
     248                }
     249                return '';
     250            }
     251        }
     252        return parent::get_field_value($key, $field, $post_data);
     253    }
     254
    223255    private function update_wc_smart_cod( $settings, $restriction_settings ) {
    224256
     
    258290    }
    259291
     292    /**
     293     * Check if a string starts with any of the prefixes in an array.
     294     *
     295     * @param string $haystack   The string to check.
     296     * @param array  $prefixes   Array of possible prefixes.
     297     * @return bool              True if any prefix matches the start of the string.
     298     */
     299    protected function has_prefix_in_array($haystack, $prefixes) {
     300        foreach ($prefixes as $prefix) {
     301            if (strncmp($haystack, $prefix, strlen($prefix)) === 0) {
     302                return true;
     303            }
     304        }
     305        return false;
     306    }
     307
    260308    protected function analyze_fields( $form_fields, $settings, $restriction_settings, $old_wc_smart_cod ) {
    261309
    262         $fields = array();
    263310        $fee_settings = array_key_exists( 'fee_settings', $settings ) ? $settings[ 'fee_settings' ] : false;
    264311        $fee_settings = $fee_settings ? json_decode( $fee_settings, true ) : array();
     
    274321            $class_arr = explode( ' ', $field[ 'class' ] );
    275322
     323            /**
     324             * - Checks if the current field has the 'wc-smart-cod-restriction' class:
     325             *   - Determines whether the restriction mode should be 'enable' or 'disable' based on $restriction_settings.
     326             *   - Updates the field title to reflect the enabled state if applicable.
     327             *   - Initializes restriction settings for new fields after plugin update.
     328             *   - Sets a custom data attribute 'data-mode' to indicate the current mode.
     329             */
    276330            if( in_array( 'wc-smart-cod-restriction', $class_arr ) ) {
    277331                // determine include or exclude
     
    299353            }
    300354
     355            /*   - Checks if the current field has the 'wc-smart-cod-percentage' class:
     356             *   - Ensures the fee type is set (defaults to 'fixed' if not present).
     357             *   - Marks that fee settings need to be updated if a new key is added.
     358             */
    301359            if( in_array( 'wc-smart-cod-percentage', $class_arr ) ) {
    302360
     
    311369            }
    312370
     371            if ($this->settings_manager && count($this->settings_manager->e) > 0) {
     372                if ($this->has_prefix_in_array($key, $this->settings_manager->e)) {
     373               
     374                    if(!in_array($key, $this->settings_manager->d)) {
     375                        $needle = $this->get_dsb_key(true);
     376                        $form_fields[ $key ][ $this->get_dsb_key() ] = true;
     377                        $form_fields[ $key ][ $needle ] = $field[ $needle ] . ' wc-smart-cod-pro-field';
     378                    }
     379                   
     380                }
     381            }
    313382        }
    314383
     
    336405    }
    337406
     407    private function get_dsb_key( $needle = false ) {
     408        return $needle ? "class" : "disabled";
     409    }
     410
    338411    public function extend_cod( $form_fields ) {
    339412        $this->prepared_fields = $this->get_prepared_fields();
     
    389462        $this->new_wc = class_exists( 'WC_Shipping_Zones' ) ? true : false;
    390463        $existing_settings = $this->settings;
    391         $existing_zone_restrictions = array();
    392464        $countries = new WC_Countries;
    393465        $states = $countries->get_allowed_country_states();
     
    468540                    'data-placeholder' => __( 'Select shipping zones', 'wc-smart-cod' ),
    469541                    'data-name' => 'shipping_zone_restrictions'
    470                 )
     542                ),
     543                'disabled' => false
    471544            );
    472545
     
    483556                'data-placeholder' => __( 'Select Countries', 'wc-smart-cod' ),
    484557                'data-name' => 'country_restrictions'
    485             )
     558            ),
     559            'disabled' => false
    486560        );
    487561
     
    496570                'data-placeholder' => __( 'Select States', 'wc-smart-cod' ),
    497571                'data-name' => 'state_restrictions'
    498             )
     572            ),
     573            'disabled' => false
    499574        );
    500575
     
    506581            'custom_attributes' => array(
    507582                'data-name' => 'restrict_postals'
    508             )
     583            ),
     584            'disabled' => false
    509585        );
    510586
     
    516592            'custom_attributes' => array(
    517593                'data-name' => 'city_restrictions'
    518             )
     594            ),
     595            'disabled' => false
    519596        );
    520597
     
    527604            'custom_attributes' => array(
    528605                'data-name' => 'cart_amount_restriction'
    529             )
     606            ),
     607            'disabled' => false
    530608        );
    531609
     
    540618                'data-placeholder' => __( 'Select Roles', 'wc-smart-cod' ),
    541619                'data-name' => 'user_role_restriction'
    542             )
     620            ),
     621            'disabled' => false
    543622        );
    544623
     
    553632            ),
    554633            'default' => 'one_product',
    555             'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart belongs to a restricted category. Select "all", if you want the COD to be restricted if all the cart product\'s belongs to restricted categories. Then add the restricted categories in the select field below.', 'wc-smart-cod' )
     634            'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart belongs to a restricted category. Select "all", if you want the COD to be restricted if all the cart product\'s belongs to restricted categories. Then add the restricted categories in the select field below.', 'wc-smart-cod' ),
     635            'disabled' => false
    556636        );
    557637
     
    568648                'data-name' => 'category_restriction',
    569649                'data-action' => 'wcsmartcod_json_search_categories'
    570             )
     650            ),
     651            'disabled' => false
    571652        );
    572653
     
    581662            ),
    582663            'default' => 'one_product',
    583             'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart is restricted. Select "all", if you want the COD to be restricted if all of the cart\'s product\'s are restricted. Then add the restricted products in the select field below.', 'wc-smart-cod' )
     664            'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart is restricted. Select "all", if you want the COD to be restricted if all of the cart\'s product\'s are restricted. Then add the restricted products in the select field below.', 'wc-smart-cod' ),
     665            'disabled' => false
    584666        );
    585667
     
    596678                'data-minimum_input_length' => '1',
    597679                'data-name' => 'product_restriction'
    598             )
     680            ),
     681            'disabled' => false
    599682        );
    600683
     
    609692            ),
    610693            'default' => 'one_product',
    611             'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart belongs to a restricted shipping class. Select "all", if you want the COD to be restricted if all of the cart\'s product\'s belongs to restricted shipping classes. Then add the restricted shipping classes in the select field below.', 'wc-smart-cod' )
     694            'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart belongs to a restricted shipping class. Select "all", if you want the COD to be restricted if all of the cart\'s product\'s belongs to restricted shipping classes. Then add the restricted shipping classes in the select field below.', 'wc-smart-cod' ),
     695            'disabled' => false
    612696        );
    613697
     
    622706                'data-placeholder' => __( 'Select Shipping Classes', 'wc-smart-cod' ),
    623707                'data-name' => 'shipping_class_restriction'
    624             )
     708            ),
     709            'disabled' => false
    625710        );
    626711
     
    642727            'type' => 'cod_messages',
    643728            'class' => 'wc-smart-cod-group',
    644             'description' => __( 'An informational text to display before the payment methods, when the COD method is not available for a customer. Leave it empty if you don\'t want to use this feature. You can define different messages per reason.', 'wc-smart-cod' )
     729            'description' => __( 'An informational text to display before the payment methods, when the COD method is not available for a customer. Leave it empty if you don\'t want to use this feature. You can define different messages per reason.', 'wc-smart-cod' ),
     730            'disabled' => false
    645731        );
    646732
     
    651737            'description' => __( 'The extra amount you charging for cash on delivery (leave blank or zero if you don\'t charge extra)', 'wc-smart-cod' ),
    652738            'desc_tip' => true,
    653             'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     739            'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     740            'disabled' => false
    654741        );
    655742
     
    665752            'default' => 'round_up',
    666753            'description' => __( 'Examples: Round up setting will transform 5.345&euro; to 6&euro;<br />Round down will transform it to 5&euro;.', 'wc-smart-cod' ),
    667             'desc_tip' => false
     754            'desc_tip' => false,
     755            'disabled' => false
    668756        );
    669757
     
    679767            'default' => 'disable',
    680768            'description' => __( 'Is extra fee taxable? Use this option if you have taxes enabled in your shop and you want to include tax to COD method.', 'wc-smart-cod' ),
    681             'desc_tip' => false
     769            'desc_tip' => false,
     770            'disabled' => false
    682771        );
    683772
     
    691780            'custom_attributes' => array(
    692781                'data-name' => 'nocharge_amount'
    693             )
     782            ),
     783            'disabled' => false
    694784        );
    695785
     
    712802            'default' => array( 'tax', 'shipping' ),
    713803            'description' => __( 'This setting affect those settings: "Disable extra fee if cart amount is greater than this limit." and "Disable if cart amount is greater than". <strong>It defines what is finally calculated as the cart amount.</strong>', 'wc-smart-cod' ),
    714             'desc_tip' => false
     804            'desc_tip' => false,
     805            'disabled' => false
    715806        );
    716807
     
    724815                    'desc_tip' => true,
    725816                    'class' => 'wc-smart-cod-group wc-smart-cod-percentage',
    726                     'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     817                    'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     818                    'disabled' => false
    727819                );
    728820            }
     
    748840                        'desc_tip' => true,
    749841                        'class' => 'wc-smart-cod-group wc-smart-cod-percentage',
    750                         'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     842                        'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     843                        'disabled' => false
    751844                    );
    752845
     
    786879                    'desc_tip' => true,
    787880                    'class' => 'wc-smart-cod-group wc-smart-cod-fee wc-smart-cod-percentage',
    788                     'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     881                    'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     882                    'disabled' => false
    789883                );
    790884
     
    825919                            'desc_tip' => true,
    826920                            'class' => 'wc-smart-cod-group wc-smart-cod-fee wc-smart-cod-percentage',
    827                             'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     921                            'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     922                            'disabled' => false
    828923                        );
    829924                    }
     
    838933        $form_fields[ 'fee_settings' ] = array(
    839934            'type' => 'hidden'
     935        );
     936
     937        $form_fields[ 'risk_free_advance_payment' ] = array(
     938            'title' => __( 'Partial payment amount for COD orders', 'wc-smart-cod' ),
     939            'type' => 'price',
     940            'class' => 'wc-smart-cod-group wc-smart-cod-percentage',
     941            'description' => __( 'Require customers to pay a portion of the order in advance, before processing a Cash on Delivery order.', 'wc-smart-cod' ),
     942            'desc_tip' => true,
     943            'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     944            'disabled' => true
    840945        );
    841946
     
    11171222                    unset( $settings [ $key ] );
    11181223            }
    1119 
    11201224        }
    11211225
     
    11941298                'enhanced_select' => $enhanced_select_variables,
    11951299                'restriction_settings' => ( object ) $this->get_json_settings( 'restriction_settings' ),
    1196                 'fee_settings' => ( object ) $this->get_json_settings( 'fee_settings' )
     1300                'fee_settings' => ( object ) $this->get_json_settings( 'fee_settings' ),
     1301                'pro_site_url' => $this->settings_manager->l
    11971302            );
    11981303
  • wc-smart-cod/tags/1.8.0/admin/css/wc-smart-cod-admin.css

    r2918131 r3327241  
    9292}
    9393
     94.pro-badge {
     95    margin: 5px 0;
     96}
     97
     98.pro-badge a {
     99  display: inline-block;
     100  padding: 4px 10px;
     101  font-size: 10px;
     102  font-weight: 600;
     103  color: #fff;
     104  background: #403447;
     105  border-radius: 999px;
     106  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
     107  letter-spacing: 0.5px;
     108  user-select: none;
     109  cursor: pointer;
     110  text-transform: none;
     111  text-decoration: none;
     112  transition: all 0.2s ease-in;
     113}
     114
     115.pro-badge a:hover {
     116  background-color: #481c41;
     117}
     118
     119.woocommerce_page_wc-settings-checkout-cod form h2 {
     120    padding-top: 15px;
     121}
     122
    94123@media screen and (min-width: 1200px) {
    95124
  • wc-smart-cod/tags/1.8.0/admin/js/wc-smart-cod-admin.min.js

    r2376032 r3327241  
    1 jQuery(document).ready(function(e){var t=e("#mainform"),a=e(".woocommerce-save-button"),n=e(".wc-smart-cod-group"),c=e(".wc-smartcod-categories, .wc-smartcod-products"),r=e(".wc-smartcod-products.wc-smart-cod-group"),i=e(".wc-smart-cod-restriction"),s=e(".wc-smart-cod-percentage"),o=e("body"),d=e("#woocommerce_cod_restriction_settings"),l=e("#woocommerce_cod_fee_settings"),_=e(".wsc-message-switcher"),m=e(".wsc-message"),u={},h={};smart_cod_variables.hasOwnProperty("restriction_settings")&&(u=smart_cod_variables.restriction_settings),smart_cod_variables.hasOwnProperty("fee_settings")&&(h=smart_cod_variables.fee_settings);var p={init:function(){d.parents("tr").addClass("hidden"),l.parents("tr").addClass("hidden"),i.each(function(t,a){p.enableConditional(e(this))}),s.each(function(t,a){p.enablePercentage(e(this))}),o.on("change",".wc-smart-cod-percantage-switcher",p.switchFee),o.on("click",".wc-smart-cod-mode",p.switchMode),a.click(function(e){p.validateFields(n)||e.preventDefault()}),c.each(function(t,a){p.initSelect2(e(this))}),p.fixSelect2Bug(r),_.on("change",p.changeMessageVisibility)},changeMessageVisibility:function(t){e(this);var a=e(this).val();m.addClass("hidden"),e('.wsc-message[data-restriction="'+a+'"]').removeClass("hidden")},isObjectEmpty:function(e){var t;for(t in e)return!1;return!0},switchMode:function(t){t.preventDefault();var a=e(this),n=a.data("mode"),c="enable"===n?"disable":"enable",r=a.parents("tr").find(".wc-smart-cod-restriction").data("name");"enable"!==n&&"disable"!==n||(u[r]="enable"===c?1:0,d.val(JSON.stringify(u)),a.html(c),a.data("mode",c))},switchFee:function(t){var a=e(this),n=a.prev(),c=a.val(),r=n.attr("name");h[r.slice(16)]=c,l.val(JSON.stringify(h))},enablePercentage:function(t){var a=t.parents("fieldset"),n=e('<select class="wc-smart-cod-percantage-switcher"><option value="fixed">Fixed</option><option value="percentage">%</option></select>'),c="0",r=t.attr("name").slice(16);h.hasOwnProperty(r)?c=h[r]:h[r]=c="fixed",n.val(c),a.append(n)},enableConditional:function(e){var t=e.parents("tr").find("th").find("label");if(t.length>0){var a=t.contents().get(0).nodeValue,n=a.trim().split(" ");if(n[0]){var c=n[0].toLowerCase();switch(c){case"enable":case"disable":var r=e.attr("name"),i=e.data("name");t.contents().get(0).nodeValue=t.text().replace(a,""),n.shift(),t.prepend('<a class="wc-smart-cod-mode" href="#" data-mode="'+c+'" data-input-name="'+r+'">'+c+"</a> "+n.join(" ")),u.hasOwnProperty(i)||(u[i]="enable"===c?1:0)}}}},fixSelect2Bug:function(e){var t=e.data("select2");t&&t.on("results:message",function(e){this.dropdown._resizeDropdown(),this.dropdown._positionDropdown()})},initSelect2:function(t){var a,n=t.data("action")||"woocommerce_json_search_categories";"wcsmartcod_json_search_categories"===n?a=smart_cod_variables.enhanced_select.search_categories_nonce:"woocommerce_json_search_products_and_variations"===n&&(a=smart_cod_variables.enhanced_select.search_products_nonce);var c={allowClear:!!t.data("allow_clear"),placeholder:t.data("placeholder"),minimumInputLength:t.data("minimum_input_length")?t.data("minimum_input_length"):"3",escapeMarkup:function(e){return e},ajax:{url:smart_cod_variables.enhanced_select.ajax_url,dataType:"json",delay:250,data:function(e){return{term:e.term,action:n,security:a,exclude:t.data("exclude"),include:t.data("include"),limit:t.data("limit")}},processResults:function(t){var a=[];return t&&e.each(t,function(e,t){a.push({id:e,text:t})}),{results:a}},cache:!0}};c=e.extend(c,p.getEnhancedSelectFormatString()),t.select2(c).addClass("enhanced")},validateFields:function(a){t.find(".field-error").remove();return a.each(function(t,a){if("woocommerce_cod_include_restrict_postals"!==a.id&&"woocommerce_cod_restrict_postals"!==a.id)return!0;var n=e(this),c=n.val()?n.val().replace(/\s/g,""):n.val();n.val(c)}),!0},getEnhancedSelectFormatString:function(){return{language:{errorLoading:function(){return smart_cod_variables.enhanced_select.i18n_searching},inputTooLong:function(e){var t=e.input.length-e.maximum;return 1===t?smart_cod_variables.enhanced_select.i18n_input_too_long_1:smart_cod_variables.enhanced_select.i18n_input_too_long_n.replace("%qty%",t)},inputTooShort:function(e){var t=e.minimum-e.input.length;return 1===t?smart_cod_variables.enhanced_select.i18n_input_too_short_1:smart_cod_variables.enhanced_select.i18n_input_too_short_n.replace("%qty%",t)},loadingMore:function(){return smart_cod_variables.enhanced_select.i18n_load_more},maximumSelected:function(e){return 1===e.maximum?smart_cod_variables.enhanced_select.i18n_selection_too_long_1:smart_cod_variables.enhanced_select.i18n_selection_too_long_n.replace("%qty%",e.maximum)},noResults:function(){return smart_cod_variables.enhanced_select.i18n_no_matches},searching:function(){return smart_cod_variables.enhanced_select.i18n_searching}}}}};p.init()});
     1jQuery(document).ready((function(e){var t=e("#mainform"),a=e(".woocommerce-save-button"),n=e(".wc-smart-cod-group"),r=e(".wc-smartcod-categories, .wc-smartcod-products"),i=e(".wc-smartcod-products.wc-smart-cod-group"),c=e(".wc-smart-cod-restriction"),s=e(".wc-smart-cod-percentage"),o=e("body"),d=e("#woocommerce_cod_restriction_settings"),l=e("#woocommerce_cod_fee_settings"),_=e(".wsc-message-switcher"),m=e(".wsc-message"),u=e(".wc-smart-cod-pro-field"),h={},p={},g="";smart_cod_variables.hasOwnProperty("restriction_settings")&&(h=smart_cod_variables.restriction_settings),smart_cod_variables.hasOwnProperty("fee_settings")&&(p=smart_cod_variables.fee_settings),smart_cod_variables.hasOwnProperty("pro_site_url")&&(g=smart_cod_variables.pro_site_url);var f={init:function(){d.parents("tr").addClass("hidden"),l.parents("tr").addClass("hidden"),c.each((function(t,a){f.enableConditional(e(this))})),s.each((function(t,a){f.enablePercentage(e(this))})),u.each((function(t,a){f.enableProField(e(this))})),o.on("change",".wc-smart-cod-percantage-switcher",f.switchFee),o.on("click",".wc-smart-cod-mode",f.switchMode),a.click((function(e){f.validateFields(n)||e.preventDefault()})),r.each((function(t,a){f.initSelect2(e(this))})),f.fixSelect2Bug(i),_.on("change",f.changeMessageVisibility)},changeMessageVisibility:function(t){e(this);var a=e(this).val();m.addClass("hidden"),e('.wsc-message[data-restriction="'+a+'"]').removeClass("hidden")},isObjectEmpty:function(e){var t;for(t in e)return!1;return!0},switchMode:function(t){t.preventDefault();var a=e(this),n=a.data("mode"),r="enable"===n?"disable":"enable",i=a.parents("tr").find(".wc-smart-cod-restriction").data("name");"enable"!==n&&"disable"!==n||(h[i]="enable"===r?1:0,d.val(JSON.stringify(h)),a.html(r),a.data("mode",r))},switchFee:function(t){var a=e(this),n=a.prev(),r=a.val(),i=n.attr("name");p[i.slice(16)]=r,l.val(JSON.stringify(p))},enablePercentage:function(t){var a=t.parents("fieldset"),n=e('<select class="wc-smart-cod-percantage-switcher"><option value="fixed">Fixed</option><option value="percentage">%</option></select>'),r="0",i=t.attr("name").slice(16);a.find("input").is(":disabled")&&n.prop("disabled",!0),p.hasOwnProperty(i)?r=p[i]:p[i]=r="fixed",n.val(r),a.append(n)},enableConditional:function(e){var t=e.parents("tr").find("th").find("label");if(t.length>0){var a=t.contents().get(0).nodeValue,n=a.trim().split(" ");if(n[0]){var r=n[0].toLowerCase();switch(r){case"enable":case"disable":var i=e.attr("name"),c=e.data("name");t.contents().get(0).nodeValue=t.text().replace(a,""),n.shift(),t.prepend('<a class="wc-smart-cod-mode" href="#" data-mode="'+r+'" data-input-name="'+i+'">'+r+"</a> "+n.join(" ")),h.hasOwnProperty(c)||(h[c]="enable"===r?1:0)}}}},enableProField:function(e){var t=e.parents("tr").find("th");t.length>0&&t.append('<p class="pro-badge"><a href="'+g+'" target="_blank">🚀 Available in PRO</a></p>')},fixSelect2Bug:function(e){var t=e.data("select2");t&&t.on("results:message",(function(e){this.dropdown._resizeDropdown(),this.dropdown._positionDropdown()}))},initSelect2:function(t){var a,n=t.data("action")||"woocommerce_json_search_categories";"wcsmartcod_json_search_categories"===n?a=smart_cod_variables.enhanced_select.search_categories_nonce:"woocommerce_json_search_products_and_variations"===n&&(a=smart_cod_variables.enhanced_select.search_products_nonce);var r={allowClear:!!t.data("allow_clear"),placeholder:t.data("placeholder"),minimumInputLength:t.data("minimum_input_length")?t.data("minimum_input_length"):"3",escapeMarkup:function(e){return e},ajax:{url:smart_cod_variables.enhanced_select.ajax_url,dataType:"json",delay:250,data:function(e){return{term:e.term,action:n,security:a,exclude:t.data("exclude"),include:t.data("include"),limit:t.data("limit")}},processResults:function(t){var a=[];return t&&e.each(t,(function(e,t){a.push({id:e,text:t})})),{results:a}},cache:!0}};r=e.extend(r,f.getEnhancedSelectFormatString()),t.select2(r).addClass("enhanced")},validateFields:function(a){t.find(".field-error").remove();return a.each((function(t,a){if("woocommerce_cod_include_restrict_postals"!==a.id&&"woocommerce_cod_restrict_postals"!==a.id)return!0;var n=e(this),r=n.val()?n.val().replace(/\s/g,""):n.val();n.val(r)})),!0},getEnhancedSelectFormatString:function(){return{language:{errorLoading:function(){return smart_cod_variables.enhanced_select.i18n_searching},inputTooLong:function(e){var t=e.input.length-e.maximum;return 1===t?smart_cod_variables.enhanced_select.i18n_input_too_long_1:smart_cod_variables.enhanced_select.i18n_input_too_long_n.replace("%qty%",t)},inputTooShort:function(e){var t=e.minimum-e.input.length;return 1===t?smart_cod_variables.enhanced_select.i18n_input_too_short_1:smart_cod_variables.enhanced_select.i18n_input_too_short_n.replace("%qty%",t)},loadingMore:function(){return smart_cod_variables.enhanced_select.i18n_load_more},maximumSelected:function(e){return 1===e.maximum?smart_cod_variables.enhanced_select.i18n_selection_too_long_1:smart_cod_variables.enhanced_select.i18n_selection_too_long_n.replace("%qty%",e.maximum)},noResults:function(){return smart_cod_variables.enhanced_select.i18n_no_matches},searching:function(){return smart_cod_variables.enhanced_select.i18n_searching}}}}};f.init()}));
  • wc-smart-cod/tags/1.8.0/includes/class-wc-smart-cod-notification-settings.php

    r2985727 r3327241  
    1717            $res = wp_remote_get(
    1818                $this->settings_url,
    19                 array( 'timeout' => 1 )
     19                array( 'timeout' => 5, 'headers' => $headers )
    2020            );
    2121
     
    2424            }
    2525
    26             $ok = ( $res
    27                 && isset( $res['response'] )
    28                 && isset( $res['response']['code'] )
    29                 && $res['response']['code'] === 200
    30             );
     26            $ok = $res
     27                && isset($res['response'])
     28                && isset($res['response']['code'])
     29                && $res['response']['code'] === 200;
    3130   
    3231            if($ok) {
  • wc-smart-cod/tags/1.8.0/includes/class-wc-smart-cod.php

    r3277209 r3327241  
    8080        $this->plugin_name = 'wc-smart-cod';
    8181       
    82         define( 'SMART_COD_VER', '1.7.3' );
     82        define( 'SMART_COD_VER', '1.8.0' );
    8383
    8484        self::$version = SMART_COD_VER;
    8585
    8686        $this->load_notification_manager();
     87
     88        $this->load_settings_manager();
    8789
    8890        self::setup_promos();
     
    221223    }
    222224
     225    public static function get_settings_manager() {
     226
     227        $settings = get_transient( 'wc-smart-cod-settings' );
     228
     229        if( $settings ) {
     230            return $settings;
     231        }
     232
     233        $settings_manager = new Wc_Smart_Cod_Settings_Manager( self::$pro_url );
     234        $settings = $settings_manager->get_settings_manager();
     235
     236        set_transient( 'wc-smart-cod-settings', $settings, 86400 );
     237       
     238        return $settings;
     239    }
     240
    223241    public function activate_notice() {
    224242
     
    268286    }
    269287
     288    public function load_settings_manager() {
     289        /**
     290         * Class responsible for settings manager
     291         */
     292        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wc-smart-cod-settings-manager.php';
     293    }
     294
    270295    public function load_dependencies() {
    271296
     
    339364
    340365    /**
    341      * Register all of the hooks related to the admin area functionality
    342      * of the plugin.
    343      *
    344      * @since    1.0.0
    345      * @access   private
    346      */
    347     private function define_admin_hooks() {
    348 
    349         $plugin_admin = new Wc_Smart_Cod_Admin( $this->get_plugin_name(), $this->get_version() );
    350 
    351         $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    352 
    353     }
    354 
    355     /**
    356366     * Register all of the hooks related to the public-facing functionality
    357367     * of the plugin.
  • wc-smart-cod/tags/1.8.0/wc-smart-cod.php

    r3277209 r3327241  
    1717 * Plugin URI:        https://wordpress.org/plugins/wc-smart-cod/
    1818 * Description:       A powerful plugin that extends WooCommerce COD (Cash on Delivery) Gateway, supporting multiple extra fees and a multiple factor gateway restriction.
    19  * Version:           1.7.3
     19 * Version:           1.8.0
    2020 * Author:            woosmartcod.com
    2121 * Author URI:        https://woosmartcod.com
     
    2525 * Domain Path:       /languages
    2626 * WC requires at least: 2.7
    27  * WC tested up to: 9.8.1
     27 * WC tested up to: 9.9.5
    2828 */
    2929
  • wc-smart-cod/trunk/README.txt

    r3277209 r3327241  
    33Tags: WooCommerce, Cash on Delivery, COD, COD Extra Fee, Smart COD, WooCommerce COD, Multiple Fees
    44Requires at least: 3.0.1
    5 Tested up to: 6.8
    6 Stable tag: 1.7.3
     5Tested up to: 6.8.1
     6Stable tag: 1.8.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • wc-smart-cod/trunk/admin/class-wc-smart-cod-admin.php

    r3277209 r3327241  
    5151    public $new_wc = false;
    5252
     53    private $restriction_settings = array();
     54
     55    private $fee_settings = array();
     56
     57    private $prepared_fields = array();
     58
     59    private $settings_manager = array();
     60
    5361    public function __construct() {
    5462
     
    5664        $this->plugin_name = 'wc-smart-cod';
    5765        $this->version = SMART_COD_VER;
     66       
     67        $this->settings_manager = (object)Wc_Smart_Cod::get_settings_manager();
    5868
    5969        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    6070        add_action( 'woocommerce_settings_api_form_fields_cod', array( $this, 'extend_cod' ) );
    6171        add_action( 'woocommerce_settings_api_sanitized_fields_cod', array( $this, 'clean_up_settings' ) );
     72        add_filter( 'experimental_woocommerce_admin_payment_reactify_render_sections', array( $this, 'woocommerce_smart_cod') );
    6273        add_action( 'woocommerce_delete_shipping_zone', array( $this, 'clean_up_gateway' ) );
    6374    }
     
    144155        echo '</h2>';
    145156        echo wp_kses_post( wpautop( $this->get_method_description() ) );
     157       
    146158        $template_data = array(
    147159            'promo_texts' => WC_Smart_Cod::$promo_texts,
     
    221233    }
    222234
     235    public function woocommerce_smart_cod($sections) {
     236        $cod = 'cod';
     237        return array_filter($sections, function($v) use ($cod) {
     238            return $v !== $cod;
     239        });
     240    }
     241
     242    public function get_field_value($key, $field, $post_data = array())
     243    {
     244        if ($this->has_prefix_in_array($key, $this->settings_manager->e)) {
     245            if (!in_array($key, haystack: $this->settings_manager->d)) {
     246                if (isset($this->settings[$key]) && $this->settings[$key] !== '') {
     247                    return $this->settings[$key];
     248                }
     249                return '';
     250            }
     251        }
     252        return parent::get_field_value($key, $field, $post_data);
     253    }
     254
    223255    private function update_wc_smart_cod( $settings, $restriction_settings ) {
    224256
     
    258290    }
    259291
     292    /**
     293     * Check if a string starts with any of the prefixes in an array.
     294     *
     295     * @param string $haystack   The string to check.
     296     * @param array  $prefixes   Array of possible prefixes.
     297     * @return bool              True if any prefix matches the start of the string.
     298     */
     299    protected function has_prefix_in_array($haystack, $prefixes) {
     300        foreach ($prefixes as $prefix) {
     301            if (strncmp($haystack, $prefix, strlen($prefix)) === 0) {
     302                return true;
     303            }
     304        }
     305        return false;
     306    }
     307
    260308    protected function analyze_fields( $form_fields, $settings, $restriction_settings, $old_wc_smart_cod ) {
    261309
    262         $fields = array();
    263310        $fee_settings = array_key_exists( 'fee_settings', $settings ) ? $settings[ 'fee_settings' ] : false;
    264311        $fee_settings = $fee_settings ? json_decode( $fee_settings, true ) : array();
     
    274321            $class_arr = explode( ' ', $field[ 'class' ] );
    275322
     323            /**
     324             * - Checks if the current field has the 'wc-smart-cod-restriction' class:
     325             *   - Determines whether the restriction mode should be 'enable' or 'disable' based on $restriction_settings.
     326             *   - Updates the field title to reflect the enabled state if applicable.
     327             *   - Initializes restriction settings for new fields after plugin update.
     328             *   - Sets a custom data attribute 'data-mode' to indicate the current mode.
     329             */
    276330            if( in_array( 'wc-smart-cod-restriction', $class_arr ) ) {
    277331                // determine include or exclude
     
    299353            }
    300354
     355            /*   - Checks if the current field has the 'wc-smart-cod-percentage' class:
     356             *   - Ensures the fee type is set (defaults to 'fixed' if not present).
     357             *   - Marks that fee settings need to be updated if a new key is added.
     358             */
    301359            if( in_array( 'wc-smart-cod-percentage', $class_arr ) ) {
    302360
     
    311369            }
    312370
     371            if ($this->settings_manager && count($this->settings_manager->e) > 0) {
     372                if ($this->has_prefix_in_array($key, $this->settings_manager->e)) {
     373               
     374                    if(!in_array($key, $this->settings_manager->d)) {
     375                        $needle = $this->get_dsb_key(true);
     376                        $form_fields[ $key ][ $this->get_dsb_key() ] = true;
     377                        $form_fields[ $key ][ $needle ] = $field[ $needle ] . ' wc-smart-cod-pro-field';
     378                    }
     379                   
     380                }
     381            }
    313382        }
    314383
     
    336405    }
    337406
     407    private function get_dsb_key( $needle = false ) {
     408        return $needle ? "class" : "disabled";
     409    }
     410
    338411    public function extend_cod( $form_fields ) {
    339412        $this->prepared_fields = $this->get_prepared_fields();
     
    389462        $this->new_wc = class_exists( 'WC_Shipping_Zones' ) ? true : false;
    390463        $existing_settings = $this->settings;
    391         $existing_zone_restrictions = array();
    392464        $countries = new WC_Countries;
    393465        $states = $countries->get_allowed_country_states();
     
    468540                    'data-placeholder' => __( 'Select shipping zones', 'wc-smart-cod' ),
    469541                    'data-name' => 'shipping_zone_restrictions'
    470                 )
     542                ),
     543                'disabled' => false
    471544            );
    472545
     
    483556                'data-placeholder' => __( 'Select Countries', 'wc-smart-cod' ),
    484557                'data-name' => 'country_restrictions'
    485             )
     558            ),
     559            'disabled' => false
    486560        );
    487561
     
    496570                'data-placeholder' => __( 'Select States', 'wc-smart-cod' ),
    497571                'data-name' => 'state_restrictions'
    498             )
     572            ),
     573            'disabled' => false
    499574        );
    500575
     
    506581            'custom_attributes' => array(
    507582                'data-name' => 'restrict_postals'
    508             )
     583            ),
     584            'disabled' => false
    509585        );
    510586
     
    516592            'custom_attributes' => array(
    517593                'data-name' => 'city_restrictions'
    518             )
     594            ),
     595            'disabled' => false
    519596        );
    520597
     
    527604            'custom_attributes' => array(
    528605                'data-name' => 'cart_amount_restriction'
    529             )
     606            ),
     607            'disabled' => false
    530608        );
    531609
     
    540618                'data-placeholder' => __( 'Select Roles', 'wc-smart-cod' ),
    541619                'data-name' => 'user_role_restriction'
    542             )
     620            ),
     621            'disabled' => false
    543622        );
    544623
     
    553632            ),
    554633            'default' => 'one_product',
    555             'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart belongs to a restricted category. Select "all", if you want the COD to be restricted if all the cart product\'s belongs to restricted categories. Then add the restricted categories in the select field below.', 'wc-smart-cod' )
     634            'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart belongs to a restricted category. Select "all", if you want the COD to be restricted if all the cart product\'s belongs to restricted categories. Then add the restricted categories in the select field below.', 'wc-smart-cod' ),
     635            'disabled' => false
    556636        );
    557637
     
    568648                'data-name' => 'category_restriction',
    569649                'data-action' => 'wcsmartcod_json_search_categories'
    570             )
     650            ),
     651            'disabled' => false
    571652        );
    572653
     
    581662            ),
    582663            'default' => 'one_product',
    583             'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart is restricted. Select "all", if you want the COD to be restricted if all of the cart\'s product\'s are restricted. Then add the restricted products in the select field below.', 'wc-smart-cod' )
     664            'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart is restricted. Select "all", if you want the COD to be restricted if all of the cart\'s product\'s are restricted. Then add the restricted products in the select field below.', 'wc-smart-cod' ),
     665            'disabled' => false
    584666        );
    585667
     
    596678                'data-minimum_input_length' => '1',
    597679                'data-name' => 'product_restriction'
    598             )
     680            ),
     681            'disabled' => false
    599682        );
    600683
     
    609692            ),
    610693            'default' => 'one_product',
    611             'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart belongs to a restricted shipping class. Select "all", if you want the COD to be restricted if all of the cart\'s product\'s belongs to restricted shipping classes. Then add the restricted shipping classes in the select field below.', 'wc-smart-cod' )
     694            'description' => __( 'Select "at least one", if you want the COD to be restricted when at least one product of the cart belongs to a restricted shipping class. Select "all", if you want the COD to be restricted if all of the cart\'s product\'s belongs to restricted shipping classes. Then add the restricted shipping classes in the select field below.', 'wc-smart-cod' ),
     695            'disabled' => false
    612696        );
    613697
     
    622706                'data-placeholder' => __( 'Select Shipping Classes', 'wc-smart-cod' ),
    623707                'data-name' => 'shipping_class_restriction'
    624             )
     708            ),
     709            'disabled' => false
    625710        );
    626711
     
    642727            'type' => 'cod_messages',
    643728            'class' => 'wc-smart-cod-group',
    644             'description' => __( 'An informational text to display before the payment methods, when the COD method is not available for a customer. Leave it empty if you don\'t want to use this feature. You can define different messages per reason.', 'wc-smart-cod' )
     729            'description' => __( 'An informational text to display before the payment methods, when the COD method is not available for a customer. Leave it empty if you don\'t want to use this feature. You can define different messages per reason.', 'wc-smart-cod' ),
     730            'disabled' => false
    645731        );
    646732
     
    651737            'description' => __( 'The extra amount you charging for cash on delivery (leave blank or zero if you don\'t charge extra)', 'wc-smart-cod' ),
    652738            'desc_tip' => true,
    653             'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     739            'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     740            'disabled' => false
    654741        );
    655742
     
    665752            'default' => 'round_up',
    666753            'description' => __( 'Examples: Round up setting will transform 5.345&euro; to 6&euro;<br />Round down will transform it to 5&euro;.', 'wc-smart-cod' ),
    667             'desc_tip' => false
     754            'desc_tip' => false,
     755            'disabled' => false
    668756        );
    669757
     
    679767            'default' => 'disable',
    680768            'description' => __( 'Is extra fee taxable? Use this option if you have taxes enabled in your shop and you want to include tax to COD method.', 'wc-smart-cod' ),
    681             'desc_tip' => false
     769            'desc_tip' => false,
     770            'disabled' => false
    682771        );
    683772
     
    691780            'custom_attributes' => array(
    692781                'data-name' => 'nocharge_amount'
    693             )
     782            ),
     783            'disabled' => false
    694784        );
    695785
     
    712802            'default' => array( 'tax', 'shipping' ),
    713803            'description' => __( 'This setting affect those settings: "Disable extra fee if cart amount is greater than this limit." and "Disable if cart amount is greater than". <strong>It defines what is finally calculated as the cart amount.</strong>', 'wc-smart-cod' ),
    714             'desc_tip' => false
     804            'desc_tip' => false,
     805            'disabled' => false
    715806        );
    716807
     
    724815                    'desc_tip' => true,
    725816                    'class' => 'wc-smart-cod-group wc-smart-cod-percentage',
    726                     'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     817                    'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     818                    'disabled' => false
    727819                );
    728820            }
     
    748840                        'desc_tip' => true,
    749841                        'class' => 'wc-smart-cod-group wc-smart-cod-percentage',
    750                         'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     842                        'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     843                        'disabled' => false
    751844                    );
    752845
     
    786879                    'desc_tip' => true,
    787880                    'class' => 'wc-smart-cod-group wc-smart-cod-fee wc-smart-cod-percentage',
    788                     'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     881                    'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     882                    'disabled' => false
    789883                );
    790884
     
    825919                            'desc_tip' => true,
    826920                            'class' => 'wc-smart-cod-group wc-smart-cod-fee wc-smart-cod-percentage',
    827                             'placeholder' => __( 'Enter Amount', 'wc-smart-cod' )
     921                            'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     922                            'disabled' => false
    828923                        );
    829924                    }
     
    838933        $form_fields[ 'fee_settings' ] = array(
    839934            'type' => 'hidden'
     935        );
     936
     937        $form_fields[ 'risk_free_advance_payment' ] = array(
     938            'title' => __( 'Partial payment amount for COD orders', 'wc-smart-cod' ),
     939            'type' => 'price',
     940            'class' => 'wc-smart-cod-group wc-smart-cod-percentage',
     941            'description' => __( 'Require customers to pay a portion of the order in advance, before processing a Cash on Delivery order.', 'wc-smart-cod' ),
     942            'desc_tip' => true,
     943            'placeholder' => __( 'Enter Amount', 'wc-smart-cod' ),
     944            'disabled' => true
    840945        );
    841946
     
    11171222                    unset( $settings [ $key ] );
    11181223            }
    1119 
    11201224        }
    11211225
     
    11941298                'enhanced_select' => $enhanced_select_variables,
    11951299                'restriction_settings' => ( object ) $this->get_json_settings( 'restriction_settings' ),
    1196                 'fee_settings' => ( object ) $this->get_json_settings( 'fee_settings' )
     1300                'fee_settings' => ( object ) $this->get_json_settings( 'fee_settings' ),
     1301                'pro_site_url' => $this->settings_manager->l
    11971302            );
    11981303
  • wc-smart-cod/trunk/admin/css/wc-smart-cod-admin.css

    r2918131 r3327241  
    9292}
    9393
     94.pro-badge {
     95    margin: 5px 0;
     96}
     97
     98.pro-badge a {
     99  display: inline-block;
     100  padding: 4px 10px;
     101  font-size: 10px;
     102  font-weight: 600;
     103  color: #fff;
     104  background: #403447;
     105  border-radius: 999px;
     106  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
     107  letter-spacing: 0.5px;
     108  user-select: none;
     109  cursor: pointer;
     110  text-transform: none;
     111  text-decoration: none;
     112  transition: all 0.2s ease-in;
     113}
     114
     115.pro-badge a:hover {
     116  background-color: #481c41;
     117}
     118
     119.woocommerce_page_wc-settings-checkout-cod form h2 {
     120    padding-top: 15px;
     121}
     122
    94123@media screen and (min-width: 1200px) {
    95124
  • wc-smart-cod/trunk/admin/js/wc-smart-cod-admin.min.js

    r2376032 r3327241  
    1 jQuery(document).ready(function(e){var t=e("#mainform"),a=e(".woocommerce-save-button"),n=e(".wc-smart-cod-group"),c=e(".wc-smartcod-categories, .wc-smartcod-products"),r=e(".wc-smartcod-products.wc-smart-cod-group"),i=e(".wc-smart-cod-restriction"),s=e(".wc-smart-cod-percentage"),o=e("body"),d=e("#woocommerce_cod_restriction_settings"),l=e("#woocommerce_cod_fee_settings"),_=e(".wsc-message-switcher"),m=e(".wsc-message"),u={},h={};smart_cod_variables.hasOwnProperty("restriction_settings")&&(u=smart_cod_variables.restriction_settings),smart_cod_variables.hasOwnProperty("fee_settings")&&(h=smart_cod_variables.fee_settings);var p={init:function(){d.parents("tr").addClass("hidden"),l.parents("tr").addClass("hidden"),i.each(function(t,a){p.enableConditional(e(this))}),s.each(function(t,a){p.enablePercentage(e(this))}),o.on("change",".wc-smart-cod-percantage-switcher",p.switchFee),o.on("click",".wc-smart-cod-mode",p.switchMode),a.click(function(e){p.validateFields(n)||e.preventDefault()}),c.each(function(t,a){p.initSelect2(e(this))}),p.fixSelect2Bug(r),_.on("change",p.changeMessageVisibility)},changeMessageVisibility:function(t){e(this);var a=e(this).val();m.addClass("hidden"),e('.wsc-message[data-restriction="'+a+'"]').removeClass("hidden")},isObjectEmpty:function(e){var t;for(t in e)return!1;return!0},switchMode:function(t){t.preventDefault();var a=e(this),n=a.data("mode"),c="enable"===n?"disable":"enable",r=a.parents("tr").find(".wc-smart-cod-restriction").data("name");"enable"!==n&&"disable"!==n||(u[r]="enable"===c?1:0,d.val(JSON.stringify(u)),a.html(c),a.data("mode",c))},switchFee:function(t){var a=e(this),n=a.prev(),c=a.val(),r=n.attr("name");h[r.slice(16)]=c,l.val(JSON.stringify(h))},enablePercentage:function(t){var a=t.parents("fieldset"),n=e('<select class="wc-smart-cod-percantage-switcher"><option value="fixed">Fixed</option><option value="percentage">%</option></select>'),c="0",r=t.attr("name").slice(16);h.hasOwnProperty(r)?c=h[r]:h[r]=c="fixed",n.val(c),a.append(n)},enableConditional:function(e){var t=e.parents("tr").find("th").find("label");if(t.length>0){var a=t.contents().get(0).nodeValue,n=a.trim().split(" ");if(n[0]){var c=n[0].toLowerCase();switch(c){case"enable":case"disable":var r=e.attr("name"),i=e.data("name");t.contents().get(0).nodeValue=t.text().replace(a,""),n.shift(),t.prepend('<a class="wc-smart-cod-mode" href="#" data-mode="'+c+'" data-input-name="'+r+'">'+c+"</a> "+n.join(" ")),u.hasOwnProperty(i)||(u[i]="enable"===c?1:0)}}}},fixSelect2Bug:function(e){var t=e.data("select2");t&&t.on("results:message",function(e){this.dropdown._resizeDropdown(),this.dropdown._positionDropdown()})},initSelect2:function(t){var a,n=t.data("action")||"woocommerce_json_search_categories";"wcsmartcod_json_search_categories"===n?a=smart_cod_variables.enhanced_select.search_categories_nonce:"woocommerce_json_search_products_and_variations"===n&&(a=smart_cod_variables.enhanced_select.search_products_nonce);var c={allowClear:!!t.data("allow_clear"),placeholder:t.data("placeholder"),minimumInputLength:t.data("minimum_input_length")?t.data("minimum_input_length"):"3",escapeMarkup:function(e){return e},ajax:{url:smart_cod_variables.enhanced_select.ajax_url,dataType:"json",delay:250,data:function(e){return{term:e.term,action:n,security:a,exclude:t.data("exclude"),include:t.data("include"),limit:t.data("limit")}},processResults:function(t){var a=[];return t&&e.each(t,function(e,t){a.push({id:e,text:t})}),{results:a}},cache:!0}};c=e.extend(c,p.getEnhancedSelectFormatString()),t.select2(c).addClass("enhanced")},validateFields:function(a){t.find(".field-error").remove();return a.each(function(t,a){if("woocommerce_cod_include_restrict_postals"!==a.id&&"woocommerce_cod_restrict_postals"!==a.id)return!0;var n=e(this),c=n.val()?n.val().replace(/\s/g,""):n.val();n.val(c)}),!0},getEnhancedSelectFormatString:function(){return{language:{errorLoading:function(){return smart_cod_variables.enhanced_select.i18n_searching},inputTooLong:function(e){var t=e.input.length-e.maximum;return 1===t?smart_cod_variables.enhanced_select.i18n_input_too_long_1:smart_cod_variables.enhanced_select.i18n_input_too_long_n.replace("%qty%",t)},inputTooShort:function(e){var t=e.minimum-e.input.length;return 1===t?smart_cod_variables.enhanced_select.i18n_input_too_short_1:smart_cod_variables.enhanced_select.i18n_input_too_short_n.replace("%qty%",t)},loadingMore:function(){return smart_cod_variables.enhanced_select.i18n_load_more},maximumSelected:function(e){return 1===e.maximum?smart_cod_variables.enhanced_select.i18n_selection_too_long_1:smart_cod_variables.enhanced_select.i18n_selection_too_long_n.replace("%qty%",e.maximum)},noResults:function(){return smart_cod_variables.enhanced_select.i18n_no_matches},searching:function(){return smart_cod_variables.enhanced_select.i18n_searching}}}}};p.init()});
     1jQuery(document).ready((function(e){var t=e("#mainform"),a=e(".woocommerce-save-button"),n=e(".wc-smart-cod-group"),r=e(".wc-smartcod-categories, .wc-smartcod-products"),i=e(".wc-smartcod-products.wc-smart-cod-group"),c=e(".wc-smart-cod-restriction"),s=e(".wc-smart-cod-percentage"),o=e("body"),d=e("#woocommerce_cod_restriction_settings"),l=e("#woocommerce_cod_fee_settings"),_=e(".wsc-message-switcher"),m=e(".wsc-message"),u=e(".wc-smart-cod-pro-field"),h={},p={},g="";smart_cod_variables.hasOwnProperty("restriction_settings")&&(h=smart_cod_variables.restriction_settings),smart_cod_variables.hasOwnProperty("fee_settings")&&(p=smart_cod_variables.fee_settings),smart_cod_variables.hasOwnProperty("pro_site_url")&&(g=smart_cod_variables.pro_site_url);var f={init:function(){d.parents("tr").addClass("hidden"),l.parents("tr").addClass("hidden"),c.each((function(t,a){f.enableConditional(e(this))})),s.each((function(t,a){f.enablePercentage(e(this))})),u.each((function(t,a){f.enableProField(e(this))})),o.on("change",".wc-smart-cod-percantage-switcher",f.switchFee),o.on("click",".wc-smart-cod-mode",f.switchMode),a.click((function(e){f.validateFields(n)||e.preventDefault()})),r.each((function(t,a){f.initSelect2(e(this))})),f.fixSelect2Bug(i),_.on("change",f.changeMessageVisibility)},changeMessageVisibility:function(t){e(this);var a=e(this).val();m.addClass("hidden"),e('.wsc-message[data-restriction="'+a+'"]').removeClass("hidden")},isObjectEmpty:function(e){var t;for(t in e)return!1;return!0},switchMode:function(t){t.preventDefault();var a=e(this),n=a.data("mode"),r="enable"===n?"disable":"enable",i=a.parents("tr").find(".wc-smart-cod-restriction").data("name");"enable"!==n&&"disable"!==n||(h[i]="enable"===r?1:0,d.val(JSON.stringify(h)),a.html(r),a.data("mode",r))},switchFee:function(t){var a=e(this),n=a.prev(),r=a.val(),i=n.attr("name");p[i.slice(16)]=r,l.val(JSON.stringify(p))},enablePercentage:function(t){var a=t.parents("fieldset"),n=e('<select class="wc-smart-cod-percantage-switcher"><option value="fixed">Fixed</option><option value="percentage">%</option></select>'),r="0",i=t.attr("name").slice(16);a.find("input").is(":disabled")&&n.prop("disabled",!0),p.hasOwnProperty(i)?r=p[i]:p[i]=r="fixed",n.val(r),a.append(n)},enableConditional:function(e){var t=e.parents("tr").find("th").find("label");if(t.length>0){var a=t.contents().get(0).nodeValue,n=a.trim().split(" ");if(n[0]){var r=n[0].toLowerCase();switch(r){case"enable":case"disable":var i=e.attr("name"),c=e.data("name");t.contents().get(0).nodeValue=t.text().replace(a,""),n.shift(),t.prepend('<a class="wc-smart-cod-mode" href="#" data-mode="'+r+'" data-input-name="'+i+'">'+r+"</a> "+n.join(" ")),h.hasOwnProperty(c)||(h[c]="enable"===r?1:0)}}}},enableProField:function(e){var t=e.parents("tr").find("th");t.length>0&&t.append('<p class="pro-badge"><a href="'+g+'" target="_blank">🚀 Available in PRO</a></p>')},fixSelect2Bug:function(e){var t=e.data("select2");t&&t.on("results:message",(function(e){this.dropdown._resizeDropdown(),this.dropdown._positionDropdown()}))},initSelect2:function(t){var a,n=t.data("action")||"woocommerce_json_search_categories";"wcsmartcod_json_search_categories"===n?a=smart_cod_variables.enhanced_select.search_categories_nonce:"woocommerce_json_search_products_and_variations"===n&&(a=smart_cod_variables.enhanced_select.search_products_nonce);var r={allowClear:!!t.data("allow_clear"),placeholder:t.data("placeholder"),minimumInputLength:t.data("minimum_input_length")?t.data("minimum_input_length"):"3",escapeMarkup:function(e){return e},ajax:{url:smart_cod_variables.enhanced_select.ajax_url,dataType:"json",delay:250,data:function(e){return{term:e.term,action:n,security:a,exclude:t.data("exclude"),include:t.data("include"),limit:t.data("limit")}},processResults:function(t){var a=[];return t&&e.each(t,(function(e,t){a.push({id:e,text:t})})),{results:a}},cache:!0}};r=e.extend(r,f.getEnhancedSelectFormatString()),t.select2(r).addClass("enhanced")},validateFields:function(a){t.find(".field-error").remove();return a.each((function(t,a){if("woocommerce_cod_include_restrict_postals"!==a.id&&"woocommerce_cod_restrict_postals"!==a.id)return!0;var n=e(this),r=n.val()?n.val().replace(/\s/g,""):n.val();n.val(r)})),!0},getEnhancedSelectFormatString:function(){return{language:{errorLoading:function(){return smart_cod_variables.enhanced_select.i18n_searching},inputTooLong:function(e){var t=e.input.length-e.maximum;return 1===t?smart_cod_variables.enhanced_select.i18n_input_too_long_1:smart_cod_variables.enhanced_select.i18n_input_too_long_n.replace("%qty%",t)},inputTooShort:function(e){var t=e.minimum-e.input.length;return 1===t?smart_cod_variables.enhanced_select.i18n_input_too_short_1:smart_cod_variables.enhanced_select.i18n_input_too_short_n.replace("%qty%",t)},loadingMore:function(){return smart_cod_variables.enhanced_select.i18n_load_more},maximumSelected:function(e){return 1===e.maximum?smart_cod_variables.enhanced_select.i18n_selection_too_long_1:smart_cod_variables.enhanced_select.i18n_selection_too_long_n.replace("%qty%",e.maximum)},noResults:function(){return smart_cod_variables.enhanced_select.i18n_no_matches},searching:function(){return smart_cod_variables.enhanced_select.i18n_searching}}}}};f.init()}));
  • wc-smart-cod/trunk/includes/class-wc-smart-cod-notification-settings.php

    r2985727 r3327241  
    1717            $res = wp_remote_get(
    1818                $this->settings_url,
    19                 array( 'timeout' => 1 )
     19                array( 'timeout' => 5, 'headers' => $headers )
    2020            );
    2121
     
    2424            }
    2525
    26             $ok = ( $res
    27                 && isset( $res['response'] )
    28                 && isset( $res['response']['code'] )
    29                 && $res['response']['code'] === 200
    30             );
     26            $ok = $res
     27                && isset($res['response'])
     28                && isset($res['response']['code'])
     29                && $res['response']['code'] === 200;
    3130   
    3231            if($ok) {
  • wc-smart-cod/trunk/includes/class-wc-smart-cod.php

    r3277209 r3327241  
    8080        $this->plugin_name = 'wc-smart-cod';
    8181       
    82         define( 'SMART_COD_VER', '1.7.3' );
     82        define( 'SMART_COD_VER', '1.8.0' );
    8383
    8484        self::$version = SMART_COD_VER;
    8585
    8686        $this->load_notification_manager();
     87
     88        $this->load_settings_manager();
    8789
    8890        self::setup_promos();
     
    221223    }
    222224
     225    public static function get_settings_manager() {
     226
     227        $settings = get_transient( 'wc-smart-cod-settings' );
     228
     229        if( $settings ) {
     230            return $settings;
     231        }
     232
     233        $settings_manager = new Wc_Smart_Cod_Settings_Manager( self::$pro_url );
     234        $settings = $settings_manager->get_settings_manager();
     235
     236        set_transient( 'wc-smart-cod-settings', $settings, 86400 );
     237       
     238        return $settings;
     239    }
     240
    223241    public function activate_notice() {
    224242
     
    268286    }
    269287
     288    public function load_settings_manager() {
     289        /**
     290         * Class responsible for settings manager
     291         */
     292        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wc-smart-cod-settings-manager.php';
     293    }
     294
    270295    public function load_dependencies() {
    271296
     
    339364
    340365    /**
    341      * Register all of the hooks related to the admin area functionality
    342      * of the plugin.
    343      *
    344      * @since    1.0.0
    345      * @access   private
    346      */
    347     private function define_admin_hooks() {
    348 
    349         $plugin_admin = new Wc_Smart_Cod_Admin( $this->get_plugin_name(), $this->get_version() );
    350 
    351         $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    352 
    353     }
    354 
    355     /**
    356366     * Register all of the hooks related to the public-facing functionality
    357367     * of the plugin.
  • wc-smart-cod/trunk/wc-smart-cod.php

    r3277209 r3327241  
    1717 * Plugin URI:        https://wordpress.org/plugins/wc-smart-cod/
    1818 * Description:       A powerful plugin that extends WooCommerce COD (Cash on Delivery) Gateway, supporting multiple extra fees and a multiple factor gateway restriction.
    19  * Version:           1.7.3
     19 * Version:           1.8.0
    2020 * Author:            woosmartcod.com
    2121 * Author URI:        https://woosmartcod.com
     
    2525 * Domain Path:       /languages
    2626 * WC requires at least: 2.7
    27  * WC tested up to: 9.8.1
     27 * WC tested up to: 9.9.5
    2828 */
    2929
Note: See TracChangeset for help on using the changeset viewer.