Plugin Directory

Changeset 3451269


Ignore:
Timestamp:
02/01/2026 08:10:13 AM (2 months ago)
Author:
cod24
Message:
  • Added Calc service by weight field in bulk action
Location:
cod24-shipping
Files:
33 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • cod24-shipping/trunk/assets/js/cod24-woo-admin.js

    r3399647 r3451269  
    4242                                <div class="label" style="margin-bottom:10px"><label for="custom_total_weight">`+ cod24_woo_params.options.total_weight + ` (`+ cod24_woo_params.options.wc_weight_unit + `)</label></div>
    4343                                <input type="text" class="postbox custom_total_weight" id="custom_total_weight" style="margin-bottom:0px" name="total_weight" />
     44                            </div>
     45                            <div class="cod24-fields calc-service-weight-section" style="margin-bottom:10px;">
     46                                <input type="checkbox" class="postbox is_calc_srv_by_weight" id="is_calc_srv_by_weight" style="margin-bottom:0px;height: 17px;" name="is_calc_srv_by_weight" value="yes"/>
     47                                <div class="label"><label for="is_calc_srv_by_weight">`+ cod24_woo_params.options.calc_service_by_weight + `</label></div>
    4448                            </div>
    4549                            <div class="cod24-fields">
     
    6367                        const weight_type = document.querySelector('input[name="weight_type"]:checked').value;
    6468                        const custom_total_weight = weight_type === 'custom_weight' ? document.getElementById('custom_total_weight').value : null;
     69                       
     70                        // check is calc srv by weight
     71                        const is_calc_srv_checkbox = document.querySelector('input[name="is_calc_srv_by_weight"]');
     72                        const is_calc_srv_by_weight = is_calc_srv_checkbox && is_calc_srv_checkbox.checked ? 'yes' : 'no';
     73                       
    6574                        const carton_size = document.getElementById('carton_size').value;
    6675                        const dimension_length = document.getElementById('dimension_length').value;
     
    6978                        const cod24_form_nonce = document.getElementById('cod24_form_nonce').value;
    7079
     80                        // Validation
    7181                        if (weight_type === 'custom_weight' && !custom_total_weight) {
    72                             Swal.showValidationMessage( cod24_woo_params.field_empty );
     82                            Swal.showValidationMessage(cod24_woo_params.field_empty);
     83                            return false;
    7384                        }
    74                         if (!carton_size) {
    75                             Swal.showValidationMessage( cod24_woo_params.field_empty );
     85                       
     86                        // carton size is not null
     87                        if (is_calc_srv_by_weight === 'no' && (!carton_size || carton_size === 'none')) {
     88                            Swal.showValidationMessage(cod24_woo_params.field_empty);
     89                            return false;
    7690                        }
    7791
    78                         return { weight_type, custom_total_weight, carton_size, cod24_form_nonce, dimension_length, dimension_width, dimension_height };
     92                        return {
     93                            weight_type,
     94                            custom_total_weight,
     95                            is_calc_srv_by_weight,
     96                            carton_size,
     97                            cod24_form_nonce,
     98                            dimension_length,
     99                            dimension_width,
     100                            dimension_height
     101                        };
     102                    },
     103                    showCloseButton: true,
     104                    confirmButtonText: cod24_woo_params.options.confirm_button_text,
     105                    cancelButtonText: cod24_woo_params.options.cancel_button_text,
     106                    showCancelButton: true,
     107                    didOpen: () => {
     108                        // event listener for disable carton size
     109                        const calcCheckbox = document.getElementById('is_calc_srv_by_weight');
     110                        const cartonSelect = document.getElementById('carton_size');
     111                        const dimensionInputs = [
     112                            document.getElementById('dimension_length'),
     113                            document.getElementById('dimension_width'),
     114                            document.getElementById('dimension_height')
     115                        ];
     116                       
     117                        // function for change fields
     118                        const toggleFields = () => {
     119                            const isChecked = calcCheckbox.checked;
     120                            cartonSelect.disabled = isChecked;
     121                            if (isChecked) {
     122                                cartonSelect.value = '10'; // set default
     123                            }
     124                           
     125                            // disable dimension fields
     126                            dimensionInputs.forEach(input => {
     127                                if (input) {
     128                                    input.disabled = isChecked;
     129                                    if (isChecked) {
     130                                        input.value = '';
     131                                    }
     132                                }
     133                            });
     134                        };
     135                       
     136                        toggleFields();
     137                       
     138                        // add event listener
     139                        calcCheckbox.addEventListener('change', toggleFields);
     140                       
     141                        // Event listener for weight_type
     142                        document.querySelectorAll('input[name="weight_type"]').forEach((elem) => {
     143                            elem.addEventListener('change', function () {
     144                                const custom_weight_section = document.querySelector('.custom-weight-section');
     145                                if (this.value === 'total_weight') {
     146                                    custom_weight_section.style.display = 'none';
     147                                } else {
     148                                    custom_weight_section.style.display = 'flex';
     149                                }
     150                            });
     151                        });
     152                       
     153                        // set visibility
     154                        document.querySelector('.custom-weight-section').style.display = 'none';
    79155                    },
    80156                    showCloseButton: true,
     
    94170                                weight_type: result.value.weight_type,
    95171                                custom_total_weight: result.value.custom_total_weight,
     172                                is_calc_srv_by_weight: result.value.is_calc_srv_by_weight,
    96173                                carton_size: result.value.carton_size,
    97174                                dimension_length: result.value.dimension_length,
  • cod24-shipping/trunk/cod24-shipping.php

    r3426465 r3451269  
    33Plugin Name: COD24 Shipping For Woocommerce
    44Description: This plugin is adding COD24 shipping methods to woocommerce.
    5 Version: 5.0.4
     5Version: 5.0.5
    66Author: COD24
    77Author URI: https://cod24.ir
     
    2626        public function __construct()
    2727        {
    28             define('COD24_PLUGIN_VERSION', '5.0.4');
     28            define('COD24_PLUGIN_VERSION', '5.0.5');
    2929            define('COD24_PLUGIN_DIR', plugin_dir_path(__FILE__));
    3030            define('COD24_PLUGIN_URL', plugin_dir_url(__FILE__));
  • cod24-shipping/trunk/inc/class-cod24-dokan.php

    r3426465 r3451269  
    66 * Package: COD24 Shipping
    77 * Author: COD24
    8  * Last Modified Time: 2025/10/26 (Complete Rewrite)
     8 * Last Modified Time: 2025/12/29 00:35:41
    99 * License: GPL-2.0+
    1010 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6565        public static function enqueue_vendor_assets() {
    6666            // Check if we're on Dokan vendor dashboard
    67             if ( ! dokan_is_seller_dashboard() ) {
     67            if ( function_exists('dokan_is_seller_dashboard') && ! dokan_is_seller_dashboard() ) {
    6868                return;
    6969            }
  • cod24-shipping/trunk/inc/class-cod24-woo.php

    r3426042 r3451269  
    66 * Package: COD24 Shipping
    77 * Author: COD24
    8  * Last Modified Time: 2025/09/23 22:38:16
     8 * Last Modified Time: 2025/12/28 22:30:13
    99 * License: GPL-2.0+
    1010 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    129129                        ),
    130130                        'total_weight' => esc_attr__('Total weight of order', 'cod24-shipping'),
     131                        'calc_service_by_weight' => esc_attr__('Calculate service cost by weight', 'cod24-shipping'),
    131132                        'wc_weight_unit' => esc_attr( get_option('woocommerce_weight_unit') ),
    132133                        'carton_size' => array(
     
    683684                    }
    684685                       
    685                         // check content parcel
    686                         if( isset( $_POST['content_parcel'] ) && !empty( $_POST['content_parcel'] ) )
    687                         {
    688                             $cod24_info['content_parcel'] = sanitize_textarea_field( $_POST['content_parcel'] );
    689                         }
     686                    // check content parcel
     687                    if( isset( $_POST['content_parcel'] ) && !empty( $_POST['content_parcel'] ) )
     688                    {
     689                        $cod24_info['content_parcel'] = sanitize_textarea_field( $_POST['content_parcel'] );
     690                    }
    690691                }
    691692                elseif( $old_cod24_info['shipping_type'] == 'tipax' && isset( $_POST['tipax_custom_total_weight'] ) && !empty( $_POST['tipax_custom_total_weight'] ) )
     
    15891590                        if( ! $process_only_orders && $valid_weight )
    15901591                        {
    1591                             // check carton size
    1592                             if( isset( $_POST['carton_size'] ) && !empty( $_POST['carton_size'] ) && $_POST['carton_size'] != 'none' )
    1593                             {
    1594                                 $carton_sizes = COD24_Tipax_API::get_carton_sizes();
    1595                                 $user_key_carton_size = sanitize_text_field( $_POST['carton_size'] );
    1596                                 if( in_array( $user_key_carton_size, array_keys( $carton_sizes ) ) )
    1597                                 {
    1598                                     // do nothing
    1599                                     $user_carton_size = array_search( $user_key_carton_size, array_keys( $carton_sizes ) ) + 1;
    1600                                     $result = array( 'status' => true );
    1601                                     $valid_carton_size = 1;
    1602                                 }
    1603                                 else
    1604                                 {
    1605                                     $result = array( 'status' => false, 'msg' => __('The carton size value is invalid', 'cod24-shipping') );
    1606                                     $valid_carton_size = 0;
    1607                                 }
    1608                             }
    1609                             else
    1610                             {
    1611                                 $result = array( 'status' => false, 'msg' => __('Please fill in the carton size field', 'cod24-shipping') );
    1612                                 $valid_carton_size = 0;
    1613                             }
     1592                            // check is_calc_srv_by_weight
     1593                            if( isset( $_POST['is_calc_srv_by_weight'] ) && $_POST['is_calc_srv_by_weight'] == 'yes' )
     1594                            {
     1595                                $is_calc_srv_by_weight = 'yes';
     1596                                $user_carton_size = 0; // Set carton size to 0 when calculating by weight
     1597                                $valid_carton_size = 1;
     1598                            }
     1599                            else
     1600                            {
     1601                                $is_calc_srv_by_weight = 'no';
     1602                                // check carton size
     1603                                if( isset( $_POST['carton_size'] ) && !empty( $_POST['carton_size'] ) && $_POST['carton_size'] != 'none' )
     1604                                {
     1605                                    $carton_sizes = COD24_Tipax_API::get_carton_sizes();
     1606                                    $user_key_carton_size = sanitize_text_field( $_POST['carton_size'] );
     1607                                    if( in_array( $user_key_carton_size, array_keys( $carton_sizes ) ) )
     1608                                    {
     1609                                        // do nothing
     1610                                        $user_carton_size = array_search( $user_key_carton_size, array_keys( $carton_sizes ) ) + 1;
     1611                                        $result = array( 'status' => true );
     1612                                        $valid_carton_size = 1;
     1613                                    }
     1614                                    else
     1615                                    {
     1616                                        $result = array( 'status' => false, 'msg' => __('The carton size value is invalid', 'cod24-shipping') );
     1617                                        $valid_carton_size = 0;
     1618                                    }
     1619                                }
     1620                                else
     1621                                {
     1622                                    $result = array( 'status' => false, 'msg' => __('Please fill in the carton size field', 'cod24-shipping') );
     1623                                    $valid_carton_size = 0;
     1624                                }
     1625                            }
    16141626                        }
    16151627                    }
    1616                    
    16171628                   
    16181629                    if( $valid_weight && $valid_carton_size )
     
    16811692                                                $cod24_info['distribution_type'] = 20;
    16821693                                        }
     1694
     1695                                        $cod24_info['is_calc_srv_by_weight'] = $is_calc_srv_by_weight;
    16831696                                       
    16841697                                        $order->update_meta_data( '_cod24_info', $cod24_info );
  • cod24-shipping/trunk/readme.txt

    r3426465 r3451269  
    44Requires at least: 5.0
    55Tested up to: 6.9
    6 Stable tag: 5.0.4
     6Stable tag: 5.0.5
    77License: GPL-2.0+
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4444
    4545== Changelog ==
     46
     47= 5.0.5 =
     48* Added Calc service by weight field in bulk action
    4649
    4750= 5.0.4 =
Note: See TracChangeset for help on using the changeset viewer.