Plugin Directory

Changeset 3388342


Ignore:
Timestamp:
11/02/2025 11:42:23 AM (5 months ago)
Author:
amitwpdeveloper
Message:

1.5.1 update

Location:
woo-additional-fees-on-checkout-wordpress/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • woo-additional-fees-on-checkout-wordpress/trunk/assets/css/admin-style.css

    r3232191 r3388342  
    33    font-family: raleway;
    44}
    5 .wps-afoc-main-wrap p{
    6     font-family: raleway;
    7 }
    8 .wps-afoc-main-wrap p a{
    9     text-decoration: none;
    10 }
    115.wps-afoc-main-wrap p, .select2-selection__choice__display, .wps_wafc_multiselect, .select2-results__option--selectable, .select2-search__field{
    12     font-family: raleway !important;
     6    font-family: raleway !important;
    137}
    148.select2-container--default{
     
    1610}
    1711.wps-afoc-main-wrap p a{
    18     text-decoration: none;
     12    text-decoration: none;
    1913}
    2014.wps-afoc-main-wrap .error{
     
    3024
    3125.wps-afoc-main-wrap .wps-ext-cst-fees h3{
    32     width: 97%;
     26    width: 100%;
    3327    border-bottom: 1px solid #DDD;
    3428    font-family: raleway;
     
    6559.wps-afoc-main-wrap{
    6660    background: white;
     61    display: inline-block;
    6762    padding: 15px;
     63    margin: 15px;
    6864    position:relative;
    6965    width: 70%;
     
    162158    width: 99% !important;
    163159 }
     160 .wps-afoc-main-wrap .form-table td{
     161    width: 100%;
     162 }
     163 .wps-afoc-main-wrap .form-table td p{
     164    font-size: 12px;
     165    font-style: italic;
     166    display: inline-block;
     167 }
     168  .wps-feat-not{
     169
     170    font-size: 10px;
     171    font-weight: 600;
     172    color: #e7000087;
     173
     174}
  • woo-additional-fees-on-checkout-wordpress/trunk/assets/js/wps-ext-cst.js

    r2891885 r3388342  
    88    var id = $('#ext_cst_apply_cndtn').val();
    99    $("#"+id).show();
     10   
    1011}
    1112function show_hide_cndtn_extra(s_id){
    1213    $(".cndtn_mode_extra"+s_id).hide();
     14
    1315    var id = $('#ext_cst_apply_cndtn_extra'+s_id).val();
    1416    $("#"+id+s_id).show();
    1517}
    1618function remove_fees( id ){
     19    console.log(id)
    1720    var numberCount =  $('#current_number_fees').val();
    1821    var r = confirm("Are you want to delete?");
     
    6669        var data_id = $(this).attr("data-id");
    6770        $("input[type='number']").css('border','1px solid #DDD');
    68 
    6971        //console.log(data_id);
    7072        if( data_id == 1 ){
  • woo-additional-fees-on-checkout-wordpress/trunk/classes/wps-ext-cst-admin-settings.php

    r3232191 r3388342  
    33{
    44    public static function register_admin_settings(){
    5         add_settings_section("wps-ext-cst-option-section", "Additional Fees Settings<p class='error'>You are using Basic, Free version, get the Premium, Exclusive version @ <b>19 USD</b> only, for limited time.</p>", null, "wps-ext-cst-options");
     5        add_settings_section("wps-ext-cst-option-section", "Additional Fees Settings", null, "wps-ext-cst-options");
    66
    77        register_setting("wps-ext-cst-option-section", "ext_cst_status");
     
    1717        register_setting("wps-ext-cst-option-section", "cart_no_product_max");
    1818        register_setting("wps-ext-cst-option-section", "selected_product_id");
     19        register_setting("wps-ext-cst-option-section", "selected_cat_id");
     20        register_setting("wps-ext-cst-option-section", "selected_pr_type");
    1921        register_setting("wps-ext-cst-option-section", "ext_cst_is_required");
    2022        register_setting("wps-ext-cst-option-section", "ext_cst_label_css");
    2123        register_setting("wps-ext-cst-option-section", "ext_cst_inc_ship_costs");
    2224        register_setting("wps-ext-cst-option-section", "ext_cst_inc_tax");
     25        register_setting("wps-ext-cst-option-section","ext_cst_hide_option");
     26        register_setting("wps-ext-cst-option-section","ext_cst_apply_type");
    2327
    2428
     
    3337                <div class="wps-afoc-main-wrap">
    3438                    <form method="post" action="options.php">
     39                       
    3540                        <?php
     41
    3642                        settings_fields("wps-ext-cst-option-section");
    3743                        do_settings_sections("wps-ext-cst-options");
     
    4248                        $ext_cst_amount_type = (get_option('ext_cst_amount_type')) ? get_option('ext_cst_amount_type') : 'fixed';
    4349                        $ext_cst_amount      = (get_option('ext_cst_amount')) ? get_option('ext_cst_amount') : 1;
     50                        $ext_cst_auto_checked    = (get_option('ext_cst_auto_checked')) ? get_option('ext_cst_auto_checked') : 'disable';
     51                        $ext_cst_apply_cndtn = (get_option('ext_cst_apply_cndtn')) ? get_option('ext_cst_apply_cndtn') : 'all';
     52                        $cart_total_amount_min   = (get_option('cart_total_amount_min')) ? get_option('cart_total_amount_min') : 1;
     53                        $cart_total_amount_max   = (get_option('cart_total_amount_max')) ? get_option('cart_total_amount_max') : 1;
     54                        $cart_no_product_min     = (get_option('cart_no_product_min')) ? get_option('cart_no_product_min') : 1;
     55                        $cart_no_product_max     = (get_option('cart_no_product_max')) ? get_option('cart_no_product_max') : 1;
     56                        $selected_product_id     = (get_option('selected_product_id')) ? get_option('selected_product_id') : array();
     57                        $selected_cat_id         = (get_option('selected_cat_id')) ? get_option('selected_cat_id') : array();
     58                        $selected_pr_type        = (get_option('selected_pr_type')) ? get_option('selected_pr_type') : array();
     59                       
     60                        $ext_cst_is_required     = (get_option('ext_cst_is_required')) ? get_option('ext_cst_is_required') : 'no';
    4461                        $ext_cst_label_css       = (get_option('ext_cst_label_css')) ? get_option('ext_cst_label_css') : '';
     62                        $ext_cst_inc_ship_costs  = (get_option('ext_cst_inc_ship_costs')) ? get_option('ext_cst_inc_ship_costs') : 'no';
     63                        $ext_cst_inc_tax         = (get_option('ext_cst_inc_tax')) ? get_option('ext_cst_inc_tax') : 'no';
     64                        $ext_cst_hide_option = (get_option('ext_cst_hide_option')) ? get_option('ext_cst_hide_option') : 'no';
     65                        $ext_cst_apply_type = (get_option('ext_cst_apply_type')) ? get_option('ext_cst_apply_type') : 'multiply';
     66
    4567                        $extra_options = get_option('ext_cst_extra');           
    4668                       ?>
    47                         <p>Before you start, please check <a href="https://www.wpsuperiors.com/woo-additional-fees-on-checkout/" target="_blank"><i>User Guide</i></a>. Have Fun :) </p>
     69                        <p>Before start, let's take a look at <a href="https://www.wpsuperiors.com/woo-additional-fees-on-checkout/" target="_blank">The Documentation Page</a>. </p>
    4870                        <?php settings_errors(); ?>
    49                         <table class="form-table" style="width: 63%; margin-left: auto; margin-right: auto;">
     71                        <table class="form-table" style="width: 50%; margin-left: auto; margin-right: auto;">
    5072                            <tbody>
    5173                                <tr>
     
    83105                                    <td>
    84106                                        <select name="ext_cst_inc_tax" id="ext_cst_inc_tax">
    85                                             <option>Yes</option>
    86                                             <option>No</option>
    87                                         </select>
    88                                         <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     107                                            <option value="yes" <?php if($ext_cst_inc_tax=='yes'){echo 'selected';} ?>>Yes</option>
     108                                            <option value="no" <?php if($ext_cst_inc_tax=='no'){echo 'selected';} ?>>No</option>
     109                                        </select>
    89110                                    </td>
    90111                                </tr>
     
    93114                                    <td>
    94115                                        <select name="ext_cst_inc_ship_costs" id="ext_cst_inc_ship_costs">
    95                                             <option value="yes">Yes</option>
    96                                             <option value="no">No</option>
    97                                         </select>
    98                                         <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     116                                            <option value="yes" <?php if($ext_cst_inc_ship_costs=='yes'){echo 'selected';} ?>>Yes</option>
     117                                            <option value="no" <?php if($ext_cst_inc_ship_costs=='no'){echo 'selected';} ?>>No</option>
     118                                        </select>
    99119                                    </td>
    100120                                </tr>
     
    108128                                    <th scope="row"><label><?php _e( 'Apply Condition'); ?></label></th>
    109129                                    <td>
    110                                         <select data-id="1" class="ext_cst_cndtn_dropdown">
    111                                             <option value="one_time">One Time Only</option>
    112                                             <option value="multiply">Multiplied By Product Quantity</option>
    113                                         </select>
    114                                         <p style="font-size:12px; font-style: italic;">If you want to charge additional fees for each product quantity into cart then choose <b>Multiplied By Product Quantity.</b> otherwise choose One Time Only.</p>
    115                                         <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    116                                     </td>
    117                                 </tr>
    118                                 <tr>
    119                                     <th scope="row"><label><?php _e( 'Auto-checked/Auto-applied the fees'); ?></label></th>
     130                                        <select data-id="1" class="ext_cst_cndtn_dropdown" name="ext_cst_apply_type" id="ext_cst_apply_type">
     131                                            <option value="one_time" <?php if($ext_cst_apply_type=='one_time'){echo 'selected';} ?>>One Time Only</option>
     132                                            <option value="multiply" <?php if($ext_cst_apply_type=='multiply'){echo 'selected';} ?>>Multiplied By Product Quantity</option>
     133                                        </select>
     134                                        <p>If you want to charge additional fees for each product quantity into cart then choose <b>Multiplied By Product Quantity.</b> otherwise choose One Time Only.</p>
     135                                    </td>
     136                                </tr>
     137                                <tr>
     138                                    <th scope="row">
     139                                        <label><?php _e( 'Auto-checked/Auto-applied the fees'); ?></label>
     140                                        <p class="wps-feat-not">This feature will not work for WooCommerce Checkout Blocks.</p>
     141                                    </th>
    120142                                    <td>
    121143                                        <select name="ext_cst_auto_checked" id="ext_cst_auto_checked">
    122                                             <option value="enable">Enable</option>
    123                                             <option value="disable">Disable</option>
    124                                         </select>
    125                                         <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     144                                            <option value="enable" <?php if($ext_cst_auto_checked=='enable'){echo 'selected';} ?>>Enable</option>
     145                                            <option value="disable" <?php if($ext_cst_auto_checked=='disable'){echo 'selected';} ?>>Disable</option>
     146                                        </select>
    126147                                    </td>
    127148                                </tr>
     
    130151                                    <td>
    131152                                        <select data-id="1" class="ext_cst_cndtn_dropdown" name="ext_cst_apply_cndtn" id="ext_cst_apply_cndtn" onchange="show_hide_cndtn()">
    132                                             <option>All</option>
    133                                             <option value="cart_total_amount">Cart Total Amount</option>
    134                                             <option value="cart_no_product">Number of Product on Cart</option>
    135                                             <option value="selected_product">Selected Product</option>
    136                                             <option value="selected_category">Selected Category</option>
    137                                             <option value="selected_pr_type">Selected Product Type</option>
     153                                            <option value="all" <?php if($ext_cst_apply_cndtn=='all'){echo 'selected';} ?>>All</option>
     154                                            <option value="cart_total_amount" <?php if($ext_cst_apply_cndtn=='cart_total_amount'){echo 'selected';} ?>>Cart Total Amount</option>
     155                                            <option value="cart_no_product" <?php if($ext_cst_apply_cndtn=='cart_no_product'){echo 'selected';} ?>>Number of Product on Cart</option>
     156                                            <option value="selected_product" <?php if($ext_cst_apply_cndtn=='selected_product'){echo 'selected';} ?>>Selected Product</option>
     157                                            <option value="selected_category" <?php if($ext_cst_apply_cndtn=='selected_category'){echo 'selected';} ?>>Selected Category</option>
     158                                            <option value="selected_pr_type" <?php if($ext_cst_apply_cndtn=='selected_pr_type'){echo 'selected';} ?>>Selected Product Type</option>
    138159                                        </select>
    139160                                    </td>
     
    147168                                        <label>Maximum</label>
    148169                                        <input type="number" name="cart_total_amount_max" class="small-text" id="cart_total_amount_max" value="<?php echo $cart_total_amount_max; ?>"/>
    149                                         <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    150170                                    </td>
    151171                                </tr>
     
    158178                                        <label>Maximum</label>
    159179                                        <input type="number" name="cart_no_product_max" class="small-text" id="cart_no_product_max" value="<?php echo $cart_no_product_max; ?>"/>
    160                                         <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    161180                                    </td>
    162181                                </tr>
     
    166185                                        <select name="selected_product_id[]" id="selected_product_id" multiple="multiple" class="wps_wafc_multiselect">
    167186                                            <?php
     187                                                $selected_product_id = (is_array($selected_product_id)) ? $selected_product_id : array($selected_product_id);
    168188                                                $args = array(
    169189                                                    'post_type' => 'product',
     
    173193                                                if ( $loop->have_posts() ) {
    174194                                                    while ( $loop->have_posts() ) : $loop->the_post();?>
    175                                                         <option><?php echo get_the_title(); ?></option>
     195                                                        <option value="<?php echo get_the_ID(); ?>" <?php if(in_array(get_the_ID(),$selected_product_id)){echo 'selected';} ?>><?php echo get_the_title(); ?></option>
    176196                                                        <?php
    177197                                                    endwhile;
     
    182202                                            ?>
    183203                                        </select>
    184                                         <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    185204                                    </td>
    186205                                </tr>
     
    199218                                                if ( $categories ) {
    200219                                                    foreach( $categories as $category ) :?>
    201                                                         <option><?php echo $category->name.' ('.$category->count.')'; ?></option>
     220                                                        <option value="<?php echo $category->term_id; ?>" <?php if(in_array($category->term_id,$selected_cat_id)){echo 'selected';} ?>><?php echo $category->name.' ('.$category->count.')'; ?></option>
    202221                                                        <?php
    203222                                                    endforeach;
     
    207226                                            ?>
    208227                                        </select>
    209                                         <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    210228                                    </td>
    211229                                </tr>
     
    217235                                                $pr_types = array('simple','grouped','variable','external_affiliate');
    218236                                                    foreach ( $pr_types as $types ) :?>
    219                                                         <option><?php echo str_replace("_"," / ",ucwords($types)); ?></option>
     237                                                        <option value="<?php echo $types; ?>" <?php if(in_array($types,$selected_pr_type)){echo 'selected';} ?>><?php echo str_replace("_"," / ",ucwords($types)); ?></option>
    220238                                                        <?php
    221239                                                    endforeach;
    222240                                            ?>
    223241                                        </select>
    224                                         <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    225                                     </td>
    226                                 </tr>
    227                                 <tr>
    228                                     <th scope="row"><label><?php _e( 'Required Field'); ?></label></th>
     242                                    </td>
     243                                </tr>
     244                               
     245                                <tr>
     246                                    <th scope="row">
     247                                        <label><?php _e( 'Required Field'); ?></label>
     248                                        <p class="wps-feat-not">This feature will not work for WooCommerce Checkout Blocks.</p>
     249                                    </th>
    229250                                    <td>
    230251                                        <select name="ext_cst_is_required" id="ext_cst_is_required">
    231                                             <option value="no">No</option>
    232                                             <option value="yes">Yes</option>
    233                                         </select>
    234                                         <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    235                                     </td>
    236                                 </tr>
    237                                 <tr>
    238                                     <th scope="row"><label><?php _e( 'Hide Option At Checkout'); ?></label></th>
    239                                     <td>
    240                                         <select>
    241                                             <option value="no">No</option>
    242                                             <option value="yes">Yes</option>
    243                                         </select>
    244                                         <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     252                                            <option value="no" <?php if($ext_cst_is_required=='no'){ echo 'selected';} ?>>No</option>
     253                                            <option value="yes" <?php if($ext_cst_is_required=='yes'){ echo 'selected';} ?>>Yes</option>
     254                                        </select>
     255                                    </td>
     256                                </tr>
     257                                <tr>
     258                                    <th scope="row">
     259                                        <label><?php _e( 'Hide Option At Checkout'); ?></label>
     260                                        <p class="wps-feat-not">This feature will not work for WooCommerce Checkout Blocks.</p>
     261                                    </th>
     262                                    <td>
     263                                        <select name="ext_cst_hide_option" id="ext_cst_hide_option">
     264                                            <option value="no" <?php if($ext_cst_hide_option=='no'){echo 'selected';} ?>>No</option>
     265                                            <option value="yes" <?php if($ext_cst_hide_option=='yes'){echo 'selected';} ?>>Yes</option>
     266                                        </select>
    245267                                    </td>
    246268                                </tr>
     
    251273                                    </td>
    252274                                </tr>
     275
    253276                            </tbody>
    254277                        </table>
    255                         <div id="wps_custom_fees_add_more" style="width: 64%; margin-left: auto; margin-right: auto;">
     278                        <div id="wps_custom_fees_add_more" style="width: 50%; margin-left: auto; margin-right: auto;">
    256279                            <?php
    257280
     
    260283
    261284                                    foreach ($extra_options as $option => $value) {
     285                                        $selected_cat_id_extra = isset($value['selected_cat_id_extra']) ? $value['selected_cat_id_extra'] : array();
     286                                        $selected_product_id_extra = isset($value['selected_product_id_extra']) ? $value['selected_product_id_extra'] : array();
     287                                        $selected_pr_type_extra = isset($value['selected_pr_type_extra']) ? $value['selected_pr_type_extra'] : array();
     288                                        //echo '<pre>'; print_r($value['selected_product_id_extra']); echo "</pre>";
    262289                                        ?>
    263290                                        <div class="wps-ext-cst-fees" id="fees<?php echo $option; ?>">
     
    301328                                                        <th scope="row"><label><?php _e( 'Calculate fees including TAX'); ?></label></th>
    302329                                                        <td>
    303                                                             <select>
    304                                                                 <option value="yes">Yes</option>
    305                                                                 <option value="no">No</option>
    306                                                             </select>
    307                                                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     330                                                            <select name="ext_cst_extra[<?php echo $option; ?>][inc_tax]" id="ext_cst_inc_tax_extra">
     331                                                                <option value="yes" <?php if(isset($value['inc_tax']) && $value['inc_tax']=='yes'){echo 'selected';} ?>>Yes</option>
     332                                                                <option value="no" <?php if(isset($value['inc_tax']) && $value['inc_tax']=='no'){echo 'selected';} ?>>No</option>
     333                                                            </select>
    308334                                                        </td>
    309335                                                    </tr>
     
    311337                                                        <th scope="row"><label><?php _e( 'Calculate fees including Shipping Costs'); ?></label></th>
    312338                                                        <td>
    313                                                             <select>
    314                                                                 <option value="yes">Yes</option>
    315                                                                 <option value="no">No</option>
    316                                                             </select>
    317                                                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     339                                                            <select name="ext_cst_extra[<?php echo $option; ?>][inc_ship_costs]" id="ext_cst_inc_ship_costs_extra">
     340                                                                <option value="yes" <?php if(isset($value['inc_ship_costs']) && $value['inc_ship_costs']=='yes'){echo 'selected';} ?>>Yes</option>
     341                                                                <option value="no" <?php if(isset($value['inc_ship_costs']) && $value['inc_ship_costs']=='no'){echo 'selected';} ?>>No</option>
     342                                                            </select>
    318343                                                        </td>
    319344                                                    </tr>
     
    328353                                                        <td>
    329354                                                            <select name="ext_cst_extra[<?php echo $option; ?>][apply_type]" id="ext_cst_apply_type<?php echo $option; ?>">
    330                                                                 <option>One Time Only</option>
    331                                                                 <option>Multiplied By Product Quantity</option>
     355                                                                <option value="one_time" <?php if($value['apply_type']=='one_time'){echo 'selected';} ?>>One Time Only</option>
     356                                                                <option value="multiply" <?php if($value['apply_type']=='multiply'){echo 'selected';} ?>>Multiplied By Product Quantity</option>
    332357                                                            </select>
    333358                                                            <p>If you want to charge additional fees for each product quantity into cart then choose <b>Multiplied By Product Quantity.</b> otherwise choose One Time Only.</p>
    334                                                             <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    335                                                         </td>
    336                                                     </tr>
    337                                                     <tr>
    338                                                         <th scope="row"><label><?php _e( 'Auto-checked/Auto-applied the fees'); ?><label></th>
    339                                                         <td>
    340                                                             <select>
    341                                                                 <option value="enable">Enable</option>
    342                                                                 <option value="disable">Disable</option>
    343                                                             </select>
    344                                                             <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     359                                                        </td>
     360                                                    </tr>
     361                                                    <tr>
     362                                                        <th scope="row">
     363                                                            <label><?php _e( 'Auto-checked/Auto-applied the fees'); ?><label>
     364                                                            <p class="wps-feat-not">This feature will not work for WooCommerce Checkout Blocks.</p>
     365                                                        </th>
     366                                                        <td>
     367                                                            <select name="ext_cst_extra[<?php echo $option; ?>][auto_checked]" id="ext_cst_auto_checked_extra">
     368                                                                <option value="enable" <?php if(isset($value['auto_checked']) && $value['auto_checked']=='enable'){ echo 'selected=selected';} ?>>Enable</option>
     369                                                                <option value="disable" <?php if(isset($value['auto_checked']) && $value['auto_checked']=='disable'){ echo 'selected=selected';} ?>>Disable</option>
     370                                                            </select>
    345371                                                        </td>
    346372                                                    </tr>
     
    348374                                                        <th scope="row"><label><?php _e( 'Condition'); ?><label></th>
    349375                                                        <td>
    350                                                             <select name="ext_cst_extra[<?php echo $option; ?>][apply_cndtn]" id="ext_cst_apply_cndtn_extra<?php echo $option; ?>" class="ext_cst_cndtn_dropdown" onchange="show_hide_cndtn_extra(<?php echo $option; ?>)">
    351                                                                 <option value="all">All</option>
    352                                                                 <option value="cart_total_amount">Cart Total Amount</option>
    353                                                                 <option value="cart_no_product">Number of Product on Cart</option>
    354                                                                 <option value="selected_product">Selected Product</option>
    355                                                                 <option value="selected_category">Selected Category</option>
    356                                                                 <option value="selected_pr_type">Selected Product Type</option>
    357                                                             </select>
    358                                                            
     376                                                            <select data-id="<?php echo $option; ?>" class="ext_cst_cndtn_dropdown" name="ext_cst_extra[<?php echo $option; ?>][apply_cndtn]" id="ext_cst_apply_cndtn_extra<?php echo $option; ?>" onchange="show_hide_cndtn_extra(<?php echo $option; ?>)">
     377                                                                <option value="all" <?php if($value['apply_cndtn']=='all'){ echo 'selected=selected';} ?>>All</option>
     378                                                                <option value="cart_total_amount" <?php if($value['apply_cndtn']=='cart_total_amount'){ echo 'selected=selected';} ?> >Cart Total Amount</option>
     379                                                                <option value="cart_no_product" <?php if($value['apply_cndtn']=='cart_no_product'){ echo 'selected=selected';} ?>>Number of Product on Cart</option>
     380                                                                <option value="selected_product" <?php if($value['apply_cndtn']=='selected_product'){ echo 'selected=selected';} ?>>Selected Product</option>
     381                                                                <option value="selected_category" <?php if($value['apply_cndtn']=='selected_category'){ echo 'selected=selected';} ?>>Selected Category</option>
     382                                                                <option value="selected_pr_type" <?php if($value['apply_cndtn']=='selected_pr_type'){ echo 'selected=selected';} ?>>Selected Product Type</option>
     383                                                            </select>
    359384                                                        </td>
    360385                                                    </tr>
     
    363388                                                        <td>
    364389                                                            <label>Minimum</label>
    365                                                             <input type="number" class="small-text" />
     390                                                            <input type="number" name="ext_cst_extra[<?php echo $option; ?>][cart_total_amount_min_extra]" class="small-text" id="cart_total_amount_min_extra" value="<?php echo $value['cart_total_amount_min_extra']; ?>"/>
    366391
    367392                                                            <label>Maximum</label>
    368                                                             <input type="number" class="small-text" />
    369                                                             <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     393                                                            <input type="number" name="ext_cst_extra[<?php echo $option; ?>][cart_total_amount_max_extra]" class="small-text" id="cart_total_amount_max_extra" value="<?php echo $value['cart_total_amount_max_extra']; ?>"/>
    370394                                                        </td>
    371395                                                    </tr>
     
    374398                                                        <td>
    375399                                                            <label>Minimum</label>
    376                                                             <input type="number" class="small-text" />
     400                                                            <input type="number" name="ext_cst_extra[<?php echo $option; ?>][cart_no_product_min_extra]" class="small-text" id="cart_no_product_min_extra" value="<?php echo $value['cart_no_product_min_extra']; ?>"/>
    377401
    378402                                                            <label>Maximum</label>
    379                                                             <input type="number" class="small-text" value=""/>
    380                                                             <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     403                                                            <input type="number" name="ext_cst_extra[<?php echo $option; ?>][cart_no_product_max_extra]" class="small-text" id="cart_no_product_max_extra" value="<?php echo $value['cart_no_product_max_extra']; ?>"/>
    381404                                                        </td>
    382405                                                    </tr>
     
    393416                                                                    if ( $loop->have_posts() ) {
    394417                                                                        while ( $loop->have_posts() ) : $loop->the_post();?>
    395                                                                             <option value="<?php echo get_the_ID(); ?>"><?php echo get_the_title(); ?></option>
     418                                                                            <option <?php if(in_array(get_the_ID(),$selected_product_id_extra)){ echo 'selected=selected';} ?> value="<?php echo get_the_ID(); ?>"><?php echo get_the_title(); ?></option>
    396419                                                                            <?php
    397420                                                                        endwhile;
     
    402425                                                                ?>
    403426                                                            </select>
    404                                                             <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    405427                                                        </td>
    406428                                                    </tr>
     
    419441                                                                    if ( $categories ) {
    420442                                                                        foreach( $categories as $category ) :?>
    421                                                                             <option value="<?php echo $category->term_id; ?>"><?php echo $category->name.' ('.$category->count.')'; ?></option>
     443                                                                            <option value="<?php echo $category->term_id; ?>" <?php if(in_array($category->term_id,$selected_cat_id_extra)){echo 'selected';} ?>><?php echo $category->name.' ('.$category->count.')'; ?></option>
    422444                                                                            <?php
    423445                                                                        endforeach;
     
    426448                                                                    }
    427449                                                                ?>
    428                                                             </select>
    429                                                             <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     450
     451                                                            </select>
    430452                                                        </td>
    431453                                                    </tr>
     
    437459                                                                    $pr_types = array('simple','grouped','variable','external_affiliate');
    438460                                                                        foreach ( $pr_types as $types ) :?>
    439                                                                             <option value="<?php echo $types; ?>"><?php echo str_replace("_"," / ",ucwords($types)); ?></option>
     461                                                                            <option value="<?php echo $types; ?>" <?php if(in_array($types,$selected_pr_type_extra)){echo 'selected';} ?>><?php echo str_replace("_"," / ",ucwords($types)); ?></option>
    440462                                                                            <?php
    441463                                                                        endforeach;
    442464                                                                ?>
    443465                                                            </select>
    444                                                             <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    445                                                         </td>
    446                                                     </tr>
    447                                                     <tr>
    448                                                         <th scope="row"><label><?php _e( 'Required Field'); ?></labe></td>
    449                                                         <td>
    450                                                             <select>
    451                                                                 <option value="no">No</option>
    452                                                                 <option value="yes">Yes</option>
    453                                                             </select>
    454                                                             <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    455                                                         </td>
    456                                                     </tr>
    457                                                     <tr>
    458                                                         <th scope="row"><label><?php _e( 'Hide Option At Checkout'); ?></label></th>
    459                                                         <td>
    460                                                             <select>
    461                                                                 <option value="no">No</option>
    462                                                                 <option value="yes">Yes</option>
    463                                                             </select>
    464                                                             <p class="error">Available with premium version @ <b>19 USD only</b>, for limited time.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     466                                                        </td>
     467                                                    </tr>
     468                                                    <tr>
     469                                                        <th scope="row">
     470                                                            <label><?php _e( 'Required Field'); ?></labe>
     471                                                            <p class="wps-feat-not">This feature will not work for WooCommerce Checkout Blocks.</p>
     472                                                        </th>
     473                                                        <td>
     474                                                            <select name="ext_cst_extra[<?php echo $option; ?>][ext_cst_is_required_extra]" name="" id="ext_cst_is_required_extra">
     475                                                                <option value="no" <?php if(isset($value['ext_cst_is_required_extra']) && $value['ext_cst_is_required_extra']=='no'){ echo 'selected';} ?>>No</option>
     476                                                                <option value="yes" <?php if(isset($value['ext_cst_is_required_extra']) && $value['ext_cst_is_required_extra']=='yes'){ echo 'selected';} ?>>Yes</option>
     477                                                            </select>
     478                                                        </td>
     479                                                    </tr>
     480                                                    <tr>
     481                                                        <th scope="row">
     482                                                            <label><?php _e( 'Hide Option At Checkout'); ?></label>
     483                                                            <p class="wps-feat-not">This feature will not work for WooCommerce Checkout Blocks.</p>
     484                                                        </th>
     485                                                        <td>
     486                                                            <select name="ext_cst_extra[<?php echo $option; ?>][hide_on_frontend]" id="ext_cst_hide_on_frontend<?php echo $option; ?>">
     487                                                                <option value="no" <?php if(isset($value['hide_on_frontend']) && $value['hide_on_frontend']=='no'){echo 'selected';} ?>>No</option>
     488                                                                <option value="yes" <?php if(isset($value['hide_on_frontend']) && $value['hide_on_frontend']=='yes'){echo 'selected';} ?>>Yes</option>
     489                                                            </select>
    465490                                                        </td>
    466491                                                    </tr>
     
    472497                                            function show_hide_cndtn_extra(s_id){
    473498                                                jQuery(".cndtn_mode_extra"+s_id).hide();
     499
    474500                                                var id = jQuery('#ext_cst_apply_cndtn_extra'+s_id).val();
    475501                                                jQuery("#"+id+s_id).show();
     
    483509                                                jQuery('#incShipCosts-<?php echo $option; ?>').hide(); 
    484510                                            }
     511
    485512
    486513                                        </script>
     
    528555                }
    529556            </script>
    530 
    531             <p style="width:100%; float:left; display:inline-block; margin-top:30px; font-size:12px;">After activate this plugin checkout page design looks bad? Send a scrrenshot and checkout URL at <a style="text-decoration:none;" href="mailto:[email protected]">[email protected]</a>, it will be solved for sure.
    532             <p style="margin-top:30px; font-size:12px;">Still Confused? Need our help? Feel free to write on us <a style="text-decoration:none;" href="mailto:[email protected]">[email protected]</a> OR visit <a style="text-decoration:none;" href="http://www.wpsuperiors.com/contact-us/" target="_blank">Contact Us</a></p>
     557            <p style="margin-top:30px; font-size:12px;">For any query, feel free to write on us <a style="text-decoration:none;" href="mailto:[email protected]">[email protected]</a> OR visit <a style="text-decoration:none;" href="http://www.wpsuperiors.com/contact-us/" target="_blank">Contact Us</a></p>
    533558            <p>Like this plugin? Leave 
    534559                <span style="font-size:200%;color:yellow;">&starf;</span>
  • woo-additional-fees-on-checkout-wordpress/trunk/classes/wps-ext-cst-admin.php

    r3232191 r3388342  
    11<?php
    2 
    32class WPS_EXT_CST_Admin
    43{
     
    65    {
    76        add_action( 'wp_ajax_wps_generate_new_fees', array($this,'wps_generate_new_fees' ));
    8         add_action( 'admin_notices', array($this,'show_premium_buy_notice' ));
    9         add_action( 'admin_init', array($this,'show_premium_buy_notice_dismissed' ));
    10     }
    11     public function show_premium_buy_notice() {
    12         $user_id = get_current_user_id();
    13         if ( !get_user_meta( $user_id, 'wps_premium_buy_notice' ) ){
    14             echo '<div class="notice notice-success is-dismissible" style="display:flex;">
    15                     <img src="https://wpsuperiors-media.s3.amazonaws.com/wp-content/uploads/2025/01/30163651/limited.png" />
    16                     <span style="padding-top:4%; font-size:20px;">WooCommerce Additional Fees On Checkout PREMIUM plugin at <b style="font-weight:700;">19 USD</b> only.
    17                     <a class="button button-primary" href="?wps-dismissed" style="margin-top:-5px;">Click To Grab</a></span>
    18                 </div>';
    19         }
    20     }
    21 
    22     public function show_premium_buy_notice_dismissed() {
    23         $user_id = get_current_user_id();
    24         if ( isset( $_GET['wps-dismissed'] ) ){
    25             add_user_meta( $user_id, 'wps_premium_buy_notice', 'true', true );
    26             wp_redirect( "https://www.wpsuperiors.com/shop/woo-additional-fees-on-checkout/", 301 );
    27             exit();
    28         }
    29     }
    30 
     7    }
    318    public static function init(){
    329        add_action( 'admin_menu', array( 'WPS_EXT_CST_Admin', 'add_menu_extra_fee_option' ) );
     
    4017    }
    4118    public static function selectively_enqueue_admin_script(){
     19       
    4220        wp_register_style( 'WPS_EXT_CST_SELECT2_ADMIN_CSS', WPS_EXT_CST_CSS . '/wafc-select2.min.css', false, '1.0.0' );
    4321        wp_enqueue_style( 'WPS_EXT_CST_SELECT2_ADMIN_CSS' );
    44        
     22
    4523        wp_register_style( 'WPS_EXT_CST_ADMIN_CSS', WPS_EXT_CST_CSS . '/admin-style.css', false, '1.0.0' );
    4624        wp_enqueue_style( 'WPS_EXT_CST_ADMIN_CSS' );
    4725    }
    4826    public static function wps_generate_new_fees(){
    49         $fees_number = (int)$_POST['number'];
    5027        ?>
    5128
    52         <div class="wps-ext-cst-fees" id="fees<?php echo $fees_number;?>">
     29        <div class="wps-ext-cst-fees" id="fees<?php echo $_POST['number'];?>">
    5330            <h3 style="border-bottom: 1px solid black;">
    5431                <span class="fees-title">Unlabelled Fees</span>
    55                 <span style="float:right; color:red; cursor: pointer;" class="dashicons dashicons-trash" onclick="remove_fees(<?php echo $fees_number;?>)"></span>
     32                <span style="float:right; color:red; cursor: pointer;" class="dashicons dashicons-trash" onclick="remove_fees(<?php echo $_POST['number'];?>)"></span>
    5633            </h3>
    5734            <table class="form-table">
     
    6037                        <th scope="row"><label><?php _e( 'Status'); ?><label></th>
    6138                        <td>
    62                             <select name="ext_cst_extra[<?php echo $fees_number;?>][status]" id="ext_cst_status_extra">
     39                            <select name="ext_cst_extra[<?php echo $_POST['number'];?>][status]" id="ext_cst_status_extra">
    6340                                <option value="enable">Enable</option>
    6441                                <option value="disable">Disable</option>
     
    6946                        <th scope="row"><label><?php _e( 'Label'); ?></labe></td>
    7047                        <td>
    71                             <input type="text" name="ext_cst_extra[<?php echo $fees_number;?>][label]" class="regular-text code" id="ext_cst_label_extra" value="<?php echo 'Unlabelled Fees #'.$fees_number;?>"/>
     48                            <input type="text" name="ext_cst_extra[<?php echo $_POST['number'];?>][label]" class="regular-text code" id="ext_cst_label_extra" value="<?php echo 'Unlabelled Fees #'.$_POST['number'];?>"/>
    7249                        </td>
    7350                    </tr>
     
    7552                        <th scope="row"><label><?php _e( 'Label for Billing'); ?></labe></td>
    7653                        <td>
    77                             <input type="text" name="ext_cst_extra[<?php echo $fees_number;?>][label_billing]" class="regular-text code" id="ext_cst_label_billing_extra" value="Unlabelled Fees #<?php echo $fees_number;?>"/>
     54                            <input type="text" name="ext_cst_extra[<?php echo $_POST['number'];?>][label_billing]" class="regular-text code" id="ext_cst_label_billing_extra" value="Unlabelled Fees #<?php echo $_POST['number'];?>"/>
    7855                        </td>
    7956                    </tr>
     
    8158                        <th scope="row"><label><?php _e( 'Type'); ?><label></th>
    8259                        <td>
    83                             <select name="ext_cst_extra[<?php echo $fees_number;?>][amount_type]" id="ext_cst_amount_type_extra" onchange="showHideTaxShipping(this,<?php echo $fees_number;?>)">
     60                            <select name="ext_cst_extra[<?php echo $_POST['number'];?>][amount_type]" id="ext_cst_amount_type_extra" onchange="showHideTaxShipping(this,<?php echo $_POST['number'];?>)">
    8461                                <option value="fixed">Fixed</option>
    8562                                <option value="percent">Percentage</option>
    8663                            </select>
    87                            
    88                         </td>
    89                     </tr>
    90                     <tr id="incTax-<?php echo $fees_number; ?>" class="incTax" style="display:none;">
     64                        </td>
     65                    </tr>
     66                    <tr id="incTax-<?php echo $_POST['number']; ?>" class="incTax" style="display:none;">
    9167                        <th scope="row"><label><?php _e( 'Calculate fees including TAX'); ?></label></th>
    9268                        <td>
    93                             <select>
    94                                 <option value="no">No</option>
    95                                 <option value="yes">Yes</option>
    96                             </select>
    97                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    98                         </td>
    99                     </tr>
    100                     <tr id="incShipCosts-<?php echo $fees_number; ?>" class="incShipCosts" style="display:none;">
     69                            <select name="ext_cst_extra[<?php echo $_POST['number']; ?>][inc_tax]" id="ext_cst_inc_tax_extra">
     70                                <option value="no">No</option>
     71                                <option value="yes">Yes</option>
     72                            </select>
     73                        </td>
     74                    </tr>
     75                    <tr id="incShipCosts-<?php echo $_POST['number']; ?>" class="incShipCosts" style="display:none;">
    10176                        <th scope="row"><label><?php _e( 'Calculate fees including Shipping Costs'); ?></label></th>
    10277                        <td>
    103                             <select>
    104                                 <option value="no">No</option>
    105                                 <option value="yes">Yes</option>
    106                             </select>
    107                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     78                            <select name="ext_cst_extra[<?php echo $_POST['number']; ?>][inc_ship_costs]" id="ext_cst_inc_ship_costs_extra">
     79                                <option value="no">No</option>
     80                                <option value="yes">Yes</option>
     81                            </select>
    10882                        </td>
    10983                    </tr>
     
    11286                        <th scope="row"><label><?php _e( 'Amount'); ?></labe></td>
    11387                        <td>
    114                             <input type="number" step="any" name="ext_cst_extra[<?php echo $fees_number;?>][amount]" class="fees_amount regular-text code" id="ext_cst_amount_extra<?php echo $fees_number;?>" value="1"/>
     88                            <input type="number" step="any" name="ext_cst_extra[<?php echo $_POST['number'];?>][amount]" class="fees_amount regular-text code" id="ext_cst_amount_extra<?php echo $_POST['number'];?>" value="1"/>
    11589                        </td>
    11690                    </tr>
     
    11892                        <th scope="row"><label><?php _e( 'Apply Condition'); ?></label></th>
    11993                        <td>
    120                             <select name="ext_cst_extra[<?php echo $fees_number; ?>][apply_type]" id="ext_cst_apply_type<?php echo $fees_number; ?>">
     94                            <select name="ext_cst_extra[<?php echo $_POST['number']; ?>][apply_type]" id="ext_cst_apply_type<?php echo $_POST['number']; ?>">
    12195                                <option value="one_time">One Time Only</option>
    12296                                <option value="multiply">Multiplied By Product Quantity</option>
    12397                            </select>
    12498                            <p>If you want to charge additional fees for each product quantity into cart then choose <b>Multiplied By Product Quantity.</b> otherwise choose One Time Only.</p>
    125                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    126                         </td>
    127                     </tr>
    128                     <tr>
    129                         <th scope="row"><label><?php _e( 'Auto-checked/Auto-applied the fees' ); ?><label></th>
    130                         <td>
    131                             <select>
     99                        </td>
     100                    </tr>
     101                    <tr>
     102                        <th scope="row">
     103                            <label><?php _e( 'Auto-checked/Auto-applied the fees' ); ?><label>
     104                            <p class="wps-feat-not">This feature will not work for WooCommerce Checkout Blocks.</p>
     105                        </th>
     106                        <td>
     107                            <select name="ext_cst_extra[<?php echo $_POST['number'];?>][auto_checked]" id="ext_cst_auto_checked_extra">
    132108                                <option value="disable">Disable</option>
    133109                                <option value="enable">Enable</option>
    134110                            </select>
    135                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    136111                        </td>
    137112                    </tr>
     
    139114                        <th scope="row"><label><?php _e( 'Condition'); ?><label></th>
    140115                        <td>
    141                             <select data-id="<?php echo $fees_number;?>" name="ext_cst_extra_apply_cndtn<?php echo $fees_number;?>" id="ext_cst_apply_cndtn_extra<?php echo $fees_number;?>" class="ext_cst_cndtn_dropdown"  onchange="show_hide_cndtn_extra(<?php echo $fees_number;?>)">
     116                            <select data-id="<?php echo $_POST['number'];?>" name="ext_cst_extra[<?php echo $_POST['number'];?>][apply_cndtn]" id="ext_cst_apply_cndtn_extra<?php echo $_POST['number'];?>" class="ext_cst_cndtn_dropdown" onchange="show_hide_cndtn_extra(<?php echo $_POST['number'];?>)">
    142117                                <option value="all">All</option>
    143118                                <option value="cart_total_amount">Cart Total Amount</option>
     
    149124                        </td>
    150125                    </tr>
    151                     <tr id="cart_total_amount<?php echo $fees_number;?>" class="cndtn_mode_extra<?php echo $fees_number;?>" style="display: none;">
     126                    <tr id="cart_total_amount<?php echo $_POST['number'];?>" class="cndtn_mode_extra<?php echo $_POST['number'];?>" style="display: none;">
    152127                        <th scope="row"><label><?php _e( 'Cart Amount'); ?></labe></td>
    153128                        <td>
    154129                            <label>Minimum</label>
    155                             <input type="number" class="small-text" id="cart_total_amount_min_extra" value=""/>
     130                            <input type="number" name="ext_cst_extra[<?php echo $_POST['number']; ?>][cart_total_amount_min_extra]" class="small-text" id="cart_total_amount_min_extra" value=""/>
    156131
    157132                            <label>Maximum</label>
    158                             <input type="number" class="small-text" id="cart_total_amount_max_extra" value=""/>
    159                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    160                         </td>
    161                     </tr>
    162                     <tr id="cart_no_product<?php echo $fees_number;?>" class="cndtn_mode_extra<?php echo $fees_number;?>" style="display: none;">
     133                            <input type="number" name="ext_cst_extra[<?php echo $_POST['number']; ?>][cart_total_amount_max_extra]" class="small-text" id="cart_total_amount_max_extra" value=""/>
     134                        </td>
     135                    </tr>
     136                    <tr id="cart_no_product<?php echo $_POST['number'];?>" class="cndtn_mode_extra<?php echo $_POST['number'];?>" style="display: none;">
    163137                        <th scope="row"><label><?php _e( 'No. Of Product on Cart'); ?></labe></td>
    164138                        <td>
    165139                            <label>Minimum</label>
    166                             <input type="number" class="small-text" id="cart_no_product_min_extra" value=""/>
     140                            <input type="number" name="ext_cst_extra[<?php echo $_POST['number']; ?>][cart_no_product_min_extra]" class="small-text" id="cart_no_product_min_extra" value=""/>
    167141
    168142                            <label>Maximum</label>
    169                             <input type="number" class="small-text" id="cart_no_product_max_extra" value=""/>
    170                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    171                         </td>
    172                     </tr>
    173                     <tr id="selected_product<?php echo $fees_number;?>" class="cndtn_mode_extra<?php echo $fees_number;?>" style="display: none;">
     143                            <input type="number" name="ext_cst_extra[<?php echo $_POST['number']; ?>][cart_no_product_max_extra]" class="small-text" id="cart_no_product_max_extra" value=""/>
     144                        </td>
     145                    </tr>
     146                    <tr id="selected_product<?php echo $_POST['number'];?>" class="cndtn_mode_extra<?php echo $_POST['number'];?>" style="display: none;">
    174147                        <th scope="row"><label><?php _e( 'Selected Product'); ?><label></th>
    175148                        <td>
    176                             <select name="ext_cst_extra_selected_product_id_extra" id="ext_cst_extra_selected_product_id_extra" class="wps_wafc_multiselect" multiple="multiple">
     149                            <select name="ext_cst_extra[<?php echo $_POST['number']; ?>][selected_product_id_extra][]" id="selected_product_id_extra" class="wps_wafc_multiselect" multiple="multiple">
    177150                                <?php
    178151                                    $args = array(
     
    183156                                    if ( $loop->have_posts() ) {
    184157                                        while ( $loop->have_posts() ) : $loop->the_post();?>
    185                                             <option><?php echo get_the_title(); ?></option>
     158                                            <option value="<?php echo get_the_ID(); ?>"><?php echo get_the_title(); ?></option>
    186159                                            <?php
    187160                                        endwhile;
     
    192165                                ?>
    193166                            </select>
    194                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    195                         </td>
    196                     </tr>
    197                     <tr id="selected_category<?php echo $fees_number;?>" class="cndtn_mode_extra<?php echo $fees_number;?>" style="display: none;">
     167                        </td>
     168                    </tr>
     169                    <tr id="selected_category<?php echo $_POST['number'];?>" class="cndtn_mode_extra<?php echo $_POST['number'];?>" style="display: none;">
    198170                        <th scope="row"><label><?php _e( 'Selected Product Category'); ?><label></th>
    199171                        <td>
    200                             <select name="ext_cst_extra_selected_cat_id_extra" id="ext_cst_extra_selected_cat_id_extra" class="wps_wafc_multiselect" multiple="multiple">
     172                            <select name="ext_cst_extra[<?php echo $_POST['number']; ?>][selected_cat_id_extra][]" id="selected_cat_id_extra" class="wps_wafc_multiselect" multiple="multiple">
    201173                                <?php
    202174                                    $args = array(
     
    209181                                    if ( $categories ) {
    210182                                        foreach( $categories as $category ) :?>
    211                                             <option>
     183                                            <option value="<?php echo $category->term_id; ?>">
    212184                                                <?php echo $category->name.' ('.$category->count.')'; ?>
    213185                                            </option>
     
    219191                                ?>
    220192                            </select>
    221                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    222                         </td>
    223                     </tr>
    224                     <tr id="selected_pr_type<?php echo $fees_number;?>" class="cndtn_mode_extra<?php echo $fees_number;?>" style="display: none;">
     193                        </td>
     194                    </tr>
     195                    <tr id="selected_pr_type<?php echo $_POST['number'];?>" class="cndtn_mode_extra<?php echo $_POST['number'];?>" style="display: none;">
    225196                        <th scope="row"><label><?php _e( 'Selected Product Type'); ?><label></th>
    226197                        <td>
    227                             <select name="ext_cst_extra_selected_pr_type_extra" id="ext_cst_extra_selected_pr_type_extra" class="wps_wafc_multiselect" multiple="multiple">
     198                            <select name="ext_cst_extra[<?php echo $_POST['number']; ?>][selected_pr_type_extra][]" id="selected_pr_type_extra" class="wps_wafc_multiselect" multiple="multiple">
    228199                                <?php
    229200                                    $pr_types = array('simple','grouped','variable','external_affiliate');
    230201                                    foreach ( $pr_types as $types ) :?>
    231                                         <option><?php echo str_replace("_"," / ",ucwords($types)); ?></option>
     202                                        <option value="<?php echo $types; ?>"><?php echo str_replace("_"," / ",ucwords($types)); ?></option>
    232203                                        <?php
    233204                                    endforeach;
    234205                                ?>
    235206                            </select>
    236                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    237                         </td>
    238                     </tr>
    239                     <tr>
    240                         <th scope="row"><label><?php _e( 'Required Field'); ?></labe></td>
    241                         <td>
    242                             <select>
    243                                 <option value="no">No</option>
    244                                 <option value="yes">Yes</option>
    245                             </select>
    246                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
    247                         </td>
    248                     </tr>
    249                     <tr>
    250                         <th scope="row"><label><?php _e( 'Hide Option At Checkout'); ?></label></th>
    251                         <td>
    252                             <select name="ext_cst_extra_hide_on_frontend" id="ext_cst_extra_hide_on_frontend">
    253                                 <option value="no">No</option>
    254                                 <option value="yes">Yes</option>
    255                             </select>
    256                             <p class="error">Available with premium version.<a target="_blank;" href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/"><br/>Buy Now</a>.</p>
     207                        </td>
     208                    </tr>
     209                    <tr>
     210                        <th scope="row">
     211                            <label><?php _e( 'Required Field'); ?></label>
     212                            <p class="wps-feat-not">This feature will not work for WooCommerce Checkout Blocks.</p>
     213                        </th>
     214                        <td>
     215                            <select name="ext_cst_extra[<?php echo $_POST['number']; ?>][ext_cst_is_required_extra]" name="" id="ext_cst_is_required_extra">
     216                                <option value="no">No</option>
     217                                <option value="yes">Yes</option>
     218                            </select>
     219                        </td>
     220                    </tr>
     221                    <tr>
     222                        <th scope="row">
     223                            <label><?php _e( 'Hide Option At Checkout'); ?></label>
     224                            <p class="wps-feat-not">This feature will not work for WooCommerce Checkout Blocks.</p>
     225                        </th>
     226                        <td>
     227                            <select name="ext_cst_extra[<?php echo $_POST['number']; ?>][hide_on_frontend]" id="ext_cst_hide_on_frontend<?php echo $_POST['number']; ?>">
     228                                <option value="no">No</option>
     229                                <option value="yes">Yes</option>
     230                            </select>
    257231                        </td>
    258232                    </tr>
  • woo-additional-fees-on-checkout-wordpress/trunk/classes/wps-ext-cst-extra-fees-frontend.php

    r2811248 r3388342  
    1212                    add_action( 'wp_footer', array($this,'add_extra_script_on_checkout_page' ));
    1313                    add_action( 'woocommerce_cart_calculate_fees', array($this,'calculate_extra_costs' ));
     14                    add_action('woocommerce_checkout_process', array($this,'check_required_fees_extra'));
    1415                    break;
    1516                }
     
    3334                break;
    3435
     36            case 'cart_total_amount':
     37                $cart_total = $woocommerce->cart->cart_contents_total;
     38                $cart_total_amount_min   = ($extra_rule['cart_total_amount_min_extra']) ? $extra_rule['cart_total_amount_min_extra'] : 1;
     39                $cart_total_amount_max   = ($extra_rule['cart_total_amount_max_extra']) ? $extra_rule['cart_total_amount_max_extra'] : 1;
     40
     41                if($cart_total_amount_max>=0 && $cart_total_amount_min>=0){
     42                    if ($cart_total_amount_max >=  $cart_total && $cart_total_amount_min <=  $cart_total ) {
     43                       
     44                        return true;
     45                    }
     46                    else{
     47                        return false;
     48                    }
     49                }
     50               
     51                break;
     52
     53            case 'cart_no_product':
     54                $cart_total_product      = WC()->cart->get_cart_contents_count();
     55                $cart_no_product_min     = ($extra_rule['cart_no_product_min_extra']) ? $extra_rule['cart_no_product_min_extra'] : 1;
     56                $cart_no_product_max     = ($extra_rule['cart_no_product_max_extra']) ? $extra_rule['cart_no_product_max_extra'] : 1;
     57               
     58                if($cart_no_product_max>=0 && $cart_no_product_min>=0){
     59                    if ($cart_no_product_max >=  $cart_total_product && $cart_no_product_min <=  $cart_total_product ) {
     60                       
     61                        return true;
     62                    }
     63                    else{
     64                        return false;
     65                    }
     66                }
     67               
     68               
     69                break;
     70
     71            case 'selected_product':
     72                $selected_product_id     = ($extra_rule['selected_product_id_extra']) ? array_map('intval',$extra_rule['selected_product_id_extra']) : array();
     73                if(array_intersect($selected_product_id, $products_ids_array)){
     74                    return true;
     75                }
     76                else{
     77                    return false;
     78                }
     79                break;
     80
     81            case 'selected_category':
     82                $selected_cat_ids = ($extra_rule['selected_cat_id_extra']) ? array_map('intval',$extra_rule['selected_cat_id_extra']) : array();
     83                $cat_ids = array();
     84                foreach ( wc()->cart->get_cart() as $cart_item_key => $cart_item ) {
     85                    $cat_ids = array_merge(
     86                        $cat_ids, $cart_item['data']->get_category_ids()
     87                    );
     88                }
     89
     90                if(array_intersect($selected_cat_ids, $cat_ids)){
     91                    return true;
     92                }
     93                else{
     94                    return false;
     95                }
     96                break;
     97
     98            case 'selected_pr_type':
     99                $selected_pr_type_extra = isset($extra_rule['selected_pr_type_extra']) ? $extra_rule['selected_pr_type_extra'] : array();
     100                $types = array();
     101                foreach ( wc()->cart->get_cart() as $cart_item_key => $cart_item ) {
     102                    array_push(
     103                        $types, $cart_item['data']->get_type()
     104                    );
     105                }
     106
     107                if(array_intersect($selected_pr_type_extra, $types)){
     108                    return true;
     109                }
     110                else{
     111                    return false;
     112                }
     113                break;
     114           
    35115            default:
    36116                return true;
     
    44124                foreach ($extra_options as $option => $value) {
    45125                    $status = $value['status'] ? $value['status'] : 'enable';
     126                    $auto_checked = $value['auto_checked'] ? $value['auto_checked'] : 'disable';
     127
    46128                    if( $status == 'enable' && !is_admin() ){
    47129                        $key = 'wps_ext_cst_label_extra_'.$option;
     
    55137                            </script>
    56138        <?php
     139                        if( $auto_checked == 'enable' ){
     140                            ?>
     141                            <script type="text/javascript">jQuery('#<?php echo $key; ?>').trigger('click');</script>
     142                            <?php
     143                        }
    57144                    }
    58145
     
    74161                    $field_id = 'wps_ext_cst_extra_field_'.$option;
    75162                    $label = $value['label'] ? $value['label'] : 'Unlabelled Fees';
     163                    $hide_on_frontend = $value['hide_on_frontend'] ? $value['hide_on_frontend'] : 'no';
     164
     165                    if($hide_on_frontend == 'no' ){
     166                        $wps_exts_custom_cls = 'wps_show_me';
     167                    }else{
     168                        $wps_exts_custom_cls = 'wps_hide_me';
     169                    }
    76170                    $extra_final_cost = WPS_EXT_CST_Extra_Fees_Frontend::calculate_final_cost_extra($value);
    77171
    78 
    79                     echo '<div id="'.$field_id.'">';
     172                    echo '<div id="'.$field_id.'" class="'.$wps_exts_custom_cls.'">';
    80173                        woocommerce_form_field( $key, array(
    81174                            'type'          => 'checkbox',
    82175                            'class'         => array('wps_ext_cst_label_extra_option form-row-wide'),
    83176                            'label'         => $label,
    84                             'required'      => false,
     177                            'required'      => $is_required_extra,
    85178                            'placeholder'   => __('')
    86179                            ), $checkout->get_value( $key ));
     
    93186    public static function calculate_final_cost_extra( $fees ){
    94187        global $woocommerce;
    95        
    96         $ext_ext_cst_amount_type = ($fees['amount_type']) ? $fees['amount_type'] : 'fixed';
    97         $ext_ext_cst_amount      = ($fees['amount']) ? $fees['amount'] : 1;
    98         $ext_ext_cst_apply_cndtn = ($fees['apply_cndtn']) ? $fees['apply_cndtn'] : 'all';
    99 
    100         $cost = $ext_ext_cst_amount;
     188        $products_ids_array = array();
     189        $items = $woocommerce->cart->get_cart();
     190        foreach( $items as $item => $values ){
     191            $products_ids_array[] = $values['product_id'];
     192        }
     193        $ext_ext_cst_amount_type = (isset($fees['amount_type'])) ? $fees['amount_type'] : 'fixed';
     194        $ext_ext_cst_amount      = (isset($fees['amount'])) ? $fees['amount'] : 1;
     195        $ext_ext_cst_apply_cndtn = (isset($fees['apply_cndtn'])) ? $fees['apply_cndtn'] : 'all';
     196        $selected_product_id     = (isset($fees['selected_product_id_extra'])) ? $fees['selected_product_id_extra'] : 0;
     197        $apply_type              = (isset($fees['apply_type'])) ? $fees['apply_type'] : 'one_time';
     198        $quantity = 0;
     199        if( $apply_type == 'multiply' ){
     200            if( $ext_ext_cst_apply_cndtn == 'selected_product' ){
     201               
     202                foreach ( WC()->cart->get_cart() as $cart_item ) {
     203                    if( in_array($cart_item['product_id'], $selected_product_id )){
     204                        $quantity = $cart_item['quantity'] + $quantity;
     205                    }
     206                }
     207            }else{
     208                foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
     209                   $quantity = $cart_item['quantity'] + $quantity;
     210                }
     211            }
     212            $cost = $ext_ext_cst_amount * $quantity;
     213        }else{
     214            $cost = $ext_ext_cst_amount;
     215        }
    101216
    102217        switch ($ext_ext_cst_amount_type) {
     
    105220                break;
    106221            case 'percent':
    107                 $extracost = ( $woocommerce->cart->cart_contents_total ) * $cost;
     222                $ext_cst_inc_ship_costs  = ($fees['inc_ship_costs']) ? $fees['inc_ship_costs'] : 'no';
     223                $ext_cst_inc_tax         = ($fees['inc_tax']) ? $fees['inc_tax'] : 'no';
     224               
     225                $total_tax = 0;
     226                $shipping_cost = 0;
     227                if( $ext_cst_inc_tax == 'yes' ){
     228                    foreach ( WC()->cart->get_tax_totals() as $code => $tax ) :
     229                        $total_tax = $total_tax + $tax->amount;
     230                    endforeach;
     231                }
     232
     233                if( $ext_cst_inc_ship_costs == 'yes' ){
     234                    $shipping_cost = $woocommerce->cart->get_shipping_total();
     235                }
     236
     237                $extracost = ( $woocommerce->cart->cart_contents_total + $total_tax + $shipping_cost ) * $cost;
    108238                $extracost = ( $extracost )/100;
    109239                break;
     
    116246
    117247    }
    118 
    119     public static function calculate_extra_costs( $cart ){
    120         if ( ! $_POST || ( is_admin() && ! is_ajax() ) ) {
    121             return;
    122         }
    123 
    124         if ( isset( $_POST['post_data'] ) ) {
    125             parse_str( $_POST['post_data'], $post_data );
    126         } else {
    127             $post_data = $_POST;
    128         }
    129 
    130         $extra_options = get_option('ext_cst_extra');
     248    public static function check_required_fees_extra(){
     249        $extra_options = get_option('ext_cst_extra');
    131250        if(is_array($extra_options) && !empty($extra_options)){
    132251            foreach ($extra_options as $option => $value) {
    133252                $status = $value['status'] ? $value['status'] : 'enable';
    134 
    135                 if( $status == 'enable' ){
     253                $get_cndtn = WPS_EXT_CST_Extra_Fees_Frontend::get_extra_condition($value);
     254                $is_required = ($value['ext_cst_is_required_extra']=='yes') ? true : false;
     255                if( $status == 'enable' && !is_admin() && $get_cndtn && $is_required){
    136256                    $key = 'wps_ext_cst_label_extra_'.$option;
    137                     if( array_key_exists($key,$post_data) ){
     257                    $label = $value['label'] ? $value['label'] : 'Unlabelled Fees';
     258                    if ( ! $_POST[$key] ){
     259                        wc_add_notice( __( '<b>'.$label.'</b> is a required field.' ), 'error' );
     260                    }
     261                }
     262            }
     263        }
     264       
     265    }
     266
     267    public static function calculate_extra_costs( $cart ){
     268       
     269        if( WC_Blocks_Utils::has_block_in_page( wc_get_page_id('checkout'), 'woocommerce/checkout' ) ){
     270            $extra_options = get_option('ext_cst_extra');
     271            if(is_array($extra_options) && !empty($extra_options)){
     272                foreach ($extra_options as $option => $value) {
     273                    //echo '<pre>'; print_r($value); echo '</pre>';
     274                    $status = $value['status'] ? $value['status'] : 'enable';
     275
     276                    if( $status == 'enable' ){
    138277                        $billing_label = $value['label_billing'] ? $value['label_billing'] : 'Unlabelled Fees';
    139                         $cost_key = 'cost_amount_hidden_'.$key;
    140                         $extracost = $post_data[$cost_key];
    141                         WC()->cart->add_fee( $billing_label, $extracost );
     278                        $final_cost = WPS_EXT_CST_Extra_Fees_Frontend::calculate_final_cost_extra($value);
     279
     280                        $get_cndtn = WPS_EXT_CST_Extra_Fees_Frontend::get_extra_condition($value);
     281               
     282                        if( $get_cndtn){
     283                            WC()->cart->add_fee( $billing_label, $final_cost );
     284                        }
     285                    }
     286                }
     287            }
     288        }else{
     289
     290            if ( ! $_POST || ( is_admin() && ! is_ajax() ) ) {
     291                return;
     292            }
     293
     294            if ( isset( $_POST['post_data'] ) ) {
     295                parse_str( $_POST['post_data'], $post_data );
     296            } else {
     297                $post_data = $_POST;
     298            }
     299
     300            $extra_options = get_option('ext_cst_extra');
     301            if(is_array($extra_options) && !empty($extra_options)){
     302                foreach ($extra_options as $option => $value) {
     303                    $status = $value['status'] ? $value['status'] : 'enable';
     304
     305                    if( $status == 'enable' ){
     306                        $key = 'wps_ext_cst_label_extra_'.$option;
     307                            if( array_key_exists($key,$post_data) ){
     308                                $billing_label = $value['label_billing'] ? $value['label_billing'] : 'Unlabelled Fees';
     309                               
     310                                $cost_key = 'cost_amount_hidden_'.$key;
     311                                $extracost = $post_data[$cost_key];
     312                                WC()->cart->add_fee( $billing_label, $extracost );
     313                            }
    142314                    }
    143315                }
  • woo-additional-fees-on-checkout-wordpress/trunk/classes/wps-ext-cst-frontend.php

    r2811247 r3388342  
    99            add_action( 'wp_footer', array($this,'add_script_on_checkout' ));
    1010            add_action( 'woocommerce_cart_calculate_fees', array($this,'apply_the_cost_to_cart' ));
     11            add_action('woocommerce_checkout_process', array($this,'check_required_fees'));
     12
     13
    1114        }
    1215    }
     
    2326                return true;
    2427                break;
     28
     29            case 'cart_total_amount':
     30                $cart_total = $woocommerce->cart->cart_contents_total;
     31                $cart_total_amount_min   = (get_option('cart_total_amount_min')) ? get_option('cart_total_amount_min') : 1;
     32                $cart_total_amount_max   = (get_option('cart_total_amount_max')) ? get_option('cart_total_amount_max') : 1;
     33                if($cart_total_amount_max>=0 && $cart_total_amount_min>=0){
     34                   
     35                    if ($cart_total_amount_max >=  $cart_total && $cart_total_amount_min <=  $cart_total ) {
     36                        return true;
     37
     38                    }
     39                    else{
     40                        return false;
     41                    }
     42                }
     43                break;
     44
     45            case 'cart_no_product':
     46                $cart_total_product      = WC()->cart->get_cart_contents_count();
     47                $cart_no_product_min     = (get_option('cart_no_product_min')) ? get_option('cart_no_product_min') : 1;
     48                $cart_no_product_max     = (get_option('cart_no_product_max')) ? get_option('cart_no_product_max') : 1;
     49               
     50                if($cart_no_product_max>=0 && $cart_no_product_min>=0){
     51                    if ($cart_no_product_max >=  $cart_total_product && $cart_no_product_min <=  $cart_total_product ) {
     52                       
     53                        return true;
     54                    }
     55                    else{
     56                        return false;
     57                    }
     58                }
     59                break;
     60
     61            case 'selected_product':
     62                $selected_product_id     = (get_option('selected_product_id')) ? get_option('selected_product_id') : 0;
     63                if(array_intersect($selected_product_id, $products_ids_array)){
     64                    return true;
     65                }
     66                else{
     67                    return false;
     68                }
     69                break;
     70
     71            case 'selected_category':
     72                $selected_cat_id = (get_option('selected_cat_id')) ? get_option('selected_cat_id') : array();
     73                $cat_ids = array();
     74                foreach ( wc()->cart->get_cart() as $cart_item_key => $cart_item ) {
     75                    $cat_ids = array_merge(
     76                        $cat_ids, $cart_item['data']->get_category_ids()
     77                    );
     78                }
     79                if(array_intersect($selected_cat_id, $cat_ids)){
     80                    return true;
     81                }
     82                else{
     83                    return false;
     84                }
     85                break;
     86
     87            case 'selected_category':
     88                $selected_cat_id = (get_option('selected_cat_id')) ? get_option('selected_cat_id') : array();
     89                $cat_ids = array();
     90                foreach ( wc()->cart->get_cart() as $cart_item_key => $cart_item ) {
     91                    $cat_ids = array_merge(
     92                        $cat_ids, $cart_item['data']->get_category_ids()
     93                    );
     94                }
     95                if(array_intersect($selected_cat_id, $cat_ids)){
     96                    return true;
     97                }
     98                else{
     99                    return false;
     100                }
     101                break;
     102
     103            case 'selected_pr_type':
     104                $selected_pr_type        = (get_option('selected_pr_type')) ? get_option('selected_pr_type') : array();
     105                $types = array();
     106                foreach ( wc()->cart->get_cart() as $cart_item_key => $cart_item ) {
     107                    array_push(
     108                        $types, $cart_item['data']->get_type()
     109                    );
     110                }
     111
     112                if(array_intersect($selected_pr_type, $types)){
     113                    return true;
     114                }
     115                else{
     116                    return false;
     117                }
     118                break;
     119
    25120           
    26121            default:
     
    31126    public static function add_option_to_checkout( $checkout ){
    32127        global $woocommerce;
    33         $ext_cst_apply_cndtn = 'all';
     128
     129       
     130
     131        $ext_cst_apply_cndtn = (get_option('ext_cst_apply_cndtn')) ? get_option('ext_cst_apply_cndtn') : 'all';
    34132       
    35133        $get_cndtn = WPS_EXT_CST_Frontend::get_condition($ext_cst_apply_cndtn);
     134       
    36135        if($get_cndtn){
     136            $is_required = (get_option('ext_cst_is_required')=='yes') ? true : false;
    37137            $ext_cst_label       = (get_option('ext_cst_label')) ? get_option('ext_cst_label') : 'Unlabelled Fees';
    38138
    39139            $ext_cst_amount_type = (get_option('ext_cst_amount_type')) ? get_option('ext_cst_amount_type') : 'fixed';
    40140            $ext_cst_amount      = (get_option('ext_cst_amount')) ? get_option('ext_cst_amount') : 1;
    41             $final_cost = WPS_EXT_CST_Frontend::calculate_final_cost($ext_cst_apply_cndtn,$ext_cst_amount,$ext_cst_amount_type);
    42 
    43             echo '<div id="wp_ext_cst_field">';
     141            $ext_cst_hide_option = (get_option('ext_cst_hide_option')) ? get_option('ext_cst_hide_option') : 'no';
     142
     143            $ext_cst_apply_type = (get_option('ext_cst_apply_type')) ? get_option('ext_cst_apply_type') : 'multiply';
     144
     145            if($ext_cst_hide_option == 'no' ){
     146                $wps_custom_cls = 'wps_show_me';
     147            }else{
     148                $wps_custom_cls = 'wps_hide_me';
     149            }
     150            $final_cost = WPS_EXT_CST_Frontend::calculate_final_cost($ext_cst_apply_cndtn, $ext_cst_amount,$ext_cst_amount_type,$ext_cst_apply_type);
     151
     152            echo '<div id="wp_ext_cst_field" class ="'.$wps_custom_cls.'">';
    44153            woocommerce_form_field( 'wps_ext_cst_label', array(
    45154                'type'          => 'checkbox',
    46155                'class'         => array('wps_ext_cst_label form-row-wide'),
    47156                'label'         => $ext_cst_label,
    48                 'required'      => false,
     157                'required'      => $is_required,
     158                'value'         => 158,
    49159                'placeholder'   => __('')
    50160                ), $checkout->get_value( 'wps_ext_cst_label' ));
     
    55165    }
    56166
    57     public static function calculate_final_cost( $cndtn, $amount, $type ){
     167    public static function calculate_final_cost( $cndtn, $amount, $type, $apply_type ){
    58168        global $woocommerce;
    59         $cost = $amount;
     169        $products_ids_array = array();
     170        $items = $woocommerce->cart->get_cart();
     171        foreach( $items as $item => $values ){
     172            $products_ids_array[] = $values['product_id'];
     173        }
     174        $quantity = 0;
     175        if( $apply_type == 'multiply' ){
     176            if( $cndtn == 'selected_product' ){
     177                $selected_product_id     = (get_option('selected_product_id')) ? get_option('selected_product_id') : 0;
     178               
     179                foreach ( WC()->cart->get_cart() as $cart_item ) {
     180                    if( in_array($cart_item['product_id'], $selected_product_id )){
     181                        $quantity = $cart_item['quantity'] + $quantity;
     182                    }
     183                }
     184            }else{
     185                foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
     186                   $quantity = $cart_item['quantity'] + $quantity;
     187                }
     188            }
     189           
     190            $cost = $amount * $quantity;
     191        }else{
     192            $cost = $amount;
     193        }
    60194
    61195        switch ($type) {
     
    64198                break;
    65199            case 'percent':
    66 
    67                 $extracost = ( $woocommerce->cart->cart_contents_total ) * $cost;
     200                $ext_cst_inc_ship_costs  = (get_option('ext_cst_inc_ship_costs')) ? get_option('ext_cst_inc_ship_costs') : 'no';
     201                $ext_cst_inc_tax         = (get_option('ext_cst_inc_tax')) ? get_option('ext_cst_inc_tax') : 'no';
     202               
     203                $total_tax = 0;
     204                $shipping_cost = 0;
     205                if( $ext_cst_inc_tax == 'yes' ){
     206                    foreach ( WC()->cart->get_tax_totals() as $code => $tax ) :
     207                        $total_tax = $total_tax + $tax->amount;
     208                    endforeach;
     209                }
     210
     211                if( $ext_cst_inc_ship_costs == 'yes' ){
     212                    $shipping_cost = $woocommerce->cart->get_shipping_total();
     213                }
     214
     215                $extracost = ( $woocommerce->cart->cart_contents_total + $total_tax + $shipping_cost ) * $cost;
    68216                $extracost = ( $extracost )/100;
    69217                break;
     
    76224    }
    77225
     226    public static function check_required_fees(){
     227        $ext_cst_label       = (get_option('ext_cst_label')) ? get_option('ext_cst_label') : 'Unlabelled Fees';
     228        $is_required = (get_option('ext_cst_is_required')=='yes') ? true : false;
     229        $ext_cst_apply_cndtn = (get_option('ext_cst_apply_cndtn')) ? get_option('ext_cst_apply_cndtn') : 'all';
     230        $get_cndtn = WPS_EXT_CST_Frontend::get_condition($ext_cst_apply_cndtn);
     231        if($is_required && $get_cndtn){
     232            if ( ! $_POST['wps_ext_cst_label'] ){
     233                wc_add_notice( __( '<b>'.$ext_cst_label.'</b> is a required field.' ), 'error' );
     234            }
     235        }
     236    }
     237
    78238    public static function add_script_on_checkout(){
    79239        if (is_checkout()) {
    80240            $ext_cst_label_css   = (get_option('ext_cst_label_css')) ? get_option('ext_cst_label_css') : '';
     241            $ext_cst_auto_checked   = (get_option('ext_cst_auto_checked')) ? get_option('ext_cst_auto_checked') : 'disable';
    81242        ?>
    82243            <script type="text/javascript">
     
    89250            <style>
    90251                <?php echo $ext_cst_label_css; ?>
     252                .wps_hide_me{ display: none !important; }
    91253            </style>
    92254        <?php
    93255        }
    94        
     256        if( $ext_cst_auto_checked == 'enable' ){
     257            ?>
     258            <script type="text/javascript">jQuery('#wps_ext_cst_label').trigger('click');</script>
     259            <?php
     260        }
    95261    }
    96262
    97263    public static function apply_the_cost_to_cart( $cart ){
     264       
     265       
     266       
    98267        $ext_cst_label_billing  = (get_option('ext_cst_label_billing')) ? get_option('ext_cst_label_billing') : 'Unlabelled Fees';
    99268       
    100269        global $woocommerce;
    101270
    102         if ( ! $_POST || ( is_admin() && ! is_ajax() ) ) {
    103             return;
    104         }
    105 
    106         if ( isset( $_POST['post_data'] ) ) {
    107             parse_str( $_POST['post_data'], $post_data );
    108         } else {
    109             $post_data = $_POST;
    110         }
    111        // echo "<pre>"; print_r($post_data); echo "</pre>";
    112         if (isset($post_data['wps_ext_cst_label']) && isset($post_data['extra_cost_amount'])) {
    113             global $woocommerce;
    114             $extracost = $post_data['extra_cost_amount'];
    115             WC()->cart->add_fee( $ext_cst_label_billing, $extracost );
    116         }
     271        if( WC_Blocks_Utils::has_block_in_page( wc_get_page_id('checkout'), 'woocommerce/checkout' ) ){
     272
     273            $ext_cst_amount_type = (get_option('ext_cst_amount_type')) ? get_option('ext_cst_amount_type') : 'fixed';
     274            $ext_cst_amount      = (get_option('ext_cst_amount')) ? get_option('ext_cst_amount') : 1;
     275            $ext_cst_apply_type = (get_option('ext_cst_apply_type')) ? get_option('ext_cst_apply_type') : 'one_time';
     276            $ext_cst_apply_cndtn = (get_option('ext_cst_apply_cndtn')) ? get_option('ext_cst_apply_cndtn') : 'all';
     277           
     278            $final_cost = WPS_EXT_CST_Frontend::calculate_final_cost($ext_cst_apply_cndtn,$ext_cst_amount,$ext_cst_amount_type,$ext_cst_apply_type);
     279
     280            $get_cndtn = WPS_EXT_CST_Frontend::get_condition($ext_cst_apply_cndtn);
     281       
     282            if($get_cndtn){
     283                WC()->cart->add_fee( $ext_cst_label_billing, $final_cost );
     284            }
     285        }else{
     286
     287            if ( ! $_POST || ( is_admin() && ! is_ajax() ) ) {
     288                return;
     289            }
     290
     291            if ( isset( $_POST['post_data'] ) ) {
     292                parse_str( $_POST['post_data'], $post_data );
     293            } else {
     294                $post_data = $_POST;
     295            }
     296           // echo "<pre>"; print_r($post_data); echo "</pre>";
     297            if (isset($post_data['wps_ext_cst_label']) && isset($post_data['extra_cost_amount'])) {
     298                global $woocommerce;
     299                $extracost = $post_data['extra_cost_amount'];
     300                WC()->cart->add_fee( $ext_cst_label_billing, $extracost );
     301            }
     302        }
     303
     304
    117305    }
    118306
  • woo-additional-fees-on-checkout-wordpress/trunk/classes/wps-ext-cst-main.php

    r2891885 r3388342  
    1111        if( $hook  != 'woocommerce_page_wps-ext-cst-option')
    1212            return;
    13 
    1413        wp_register_script('WPS_EXT_CST_SELECT2_ADMIN_JS', WPS_EXT_CST_JS.'/wafc-select2.min.js', array('jquery'),'1.1', true);
    1514        wp_enqueue_script('WPS_EXT_CST_SELECT2_ADMIN_JS');
    16        
     15
    1716        wp_register_script('WPS_EXT_CST_ADMIN_JS', WPS_EXT_CST_JS.'/wps-ext-cst.js', array('jquery'),'1.1', true);
    1817        wp_enqueue_script('WPS_EXT_CST_ADMIN_JS');
  • woo-additional-fees-on-checkout-wordpress/trunk/readme.txt

    r3367371 r3388342  
    1111
    1212== Description ==
    13 Formerly know as WooCommerce additional Fees On Checkout. Additional Fees For WooCommerce Checkout plugin allows to create required or non-required multiple fees on checkout page to apply an fixed or percentage cost upon cart total quantity, Individual product, Cart total amount, Product category, Product type.
     13Formerly known as WooCommerce additional Fees On Checkout,allows to create required or non-required multiple fees on checkout page to apply an fixed or percentage cost upon cart total quantity, Individual product, Cart total amount, Product category, Product type. This plugin supports WooCommerce Block Checkout.
    1414
    1515= Introduction =
     
    1818
    1919In one words, Additional Fees For WooCommerce Checkout plugin makes it very simple.
     20
     21It supports WooCommerce Block Checkout.
    2022
    2123Additional Fees For WooCommerce Checkout plugin built to integrate seamlessly with WordPress WooCommerce, that gives store owners complete control to adjust Labels, amount, percentage or fixed price calculation etc.
     
    119121
    120122== Changelog ==
     123= 1.5.1 - 02nd Nov, 2025 =
     124*WooCommerce Block Checkout support*
     125*Compatibility support*
     126
    121127= 1.4.9 - 30th Jan, 2025 =
    122128*WooCommerce & WordPress compatiability update*
Note: See TracChangeset for help on using the changeset viewer.