Plugin Directory

Changeset 3343366


Ignore:
Timestamp:
08/12/2025 08:56:36 AM (5 months ago)
Author:
shiperman
Message:

Resolved product edit issue. Automatically assign 1kg default weight if missing and display admin notice on WooCommerce Orders page.

Location:
shiperman-for-woocommerce/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • shiperman-for-woocommerce/trunk/changelog.txt

    r3275398 r3343366  
    11*** WooCommerce Shiperman Changelog ***
     2
     32025-08-07 - version 1.4.1
     4* Fixed Product edit issue.
     5* Automatically assign a default weight of 1 kg when a product without defined weight is added to the cart.
     6* Added admin notice on WooCommerce Orders page regarding default shipment weight.
    27
    382025-04-16 - version 1.2.0
  • shiperman-for-woocommerce/trunk/includes/Admin/class-shiperman-admin.php

    r3281126 r3343366  
    3939
    4040        add_action('admin_notices', [$this, 'check_configuration_notice']);
     41
     42        add_action('admin_notices', [$this, 'display_admin_notice_order_page'] );
    4143    }
    4244
     
    12801282                return "$pdf_url/{$tracking_number}_{$reference_id}.pdf";
    12811283            }
    1282         }
     1284
     1285            /**
     1286             * Display an admin notice on the WooCommerce Orders page.
     1287             */
     1288            public function display_admin_notice_order_page() {
     1289                global $pagenow;
     1290                // Check if it's the WooCommerce order edit page
     1291                if ( $pagenow === 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] === 'shop_order' || $pagenow === 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'wc-orders' ) {
     1292                    echo '<div class="notice notice-error"><p style="color:red;"><strong>Note:</strong> Please enter the shipemnt weight. If left blank, a default value of 1 kg will be applied. Once the actual weight is verified, the charge will be adjusted accordingly to reflect the correct amount.</p></div>';
     1293                }
     1294            }
     1295        }
  • shiperman-for-woocommerce/trunk/includes/Admin/class-shiperman-product-validation.php

    r3242749 r3343366  
    1616    {
    1717
    18         if (!isset($_POST['woocommerce_meta_nonce']) || !check_admin_referer('woocommerce_process_product_meta', 'woocommerce_meta_nonce')) {
     18        /*if (!isset($_POST['woocommerce_meta_nonce']) || !check_admin_referer('woocommerce_process_product_meta', 'woocommerce_meta_nonce')) {
    1919            wp_die(esc_html__('Invalid nonce verification.', 'shiperman-for-woocommerce'));
    20         }
     20        }*/
     21
    2122
    2223        if (!$this->is_shiperman_enabled()) {
     
    3435        $height = isset($_POST['_height']) ? sanitize_text_field(wp_unslash($_POST['_height'])) : '';
    3536
    36         if (empty($weight) || empty($length) || empty($width) || empty($height)) {
     37        if ( empty($length) || empty($width) || empty($height)) {
    3738            $this->add_admin_notice();
    3839
    3940            // Prevent saving by triggering an error
    4041            //remove_action('save_post_product', [$this, 'validate_product_dimensions'], 10);
    41             wp_die(esc_html__('Please ensure weight, length, width, and height are set for this product when Shiperman shipping is enabled.', 'shiperman-for-woocommerce'));
     42            wp_die(esc_html__('Please ensure length, width, and height are set for this product when Shiperman shipping is enabled.', 'shiperman-for-woocommerce'));
    4243        }
    4344    }
     
    5758        });
    5859    }
     60
    5961}
  • shiperman-for-woocommerce/trunk/includes/class-shiperman-shipping-method.php

    r3281024 r3343366  
    1818        $this->title = "Shiperman Shipping";
    1919
     20
     21        $this->enabled = "yes";
    2022        // Check if there are any products missing shipping info
    21         $missing_info = $this->get_products_missing_shipping_info();
    22 
    23         if (!empty($missing_info)) {
    24             // Disable the method
    25             $this->enabled = "no";
    26             // Optional: Add admin notice
    27             // add_action('admin_notices', [$this, 'admin_notice_invalid_products']);
    28         } else {
    29             $this->enabled = "yes";
    30         }
     23        //$missing_info = $this->get_products_missing_shipping_info();
     24
     25        // if (!empty($missing_info)) {
     26        //     // Disable the method
     27        //     $this->enabled = "no";
     28        //     // Optional: Add admin notice
     29        //     // add_action('admin_notices', [$this, 'admin_notice_invalid_products']);
     30        // } else {
     31        //     $this->enabled = "yes";
     32        // }
    3133
    3234        $this->init();
     
    5355            if (! $this->is_product_shipping_info_valid($product)) {
    5456                $invalid_products[] = $product;
     57               
    5558            }
    5659        }
     
    6164    private function is_product_shipping_info_valid($product)
    6265    {
    63         return (float) $product->get_weight() > 0 &&
    64             (float) $product->get_length() > 0 &&
     66        // Allow products with missing weight (will use default 1kg)
     67        // Only require length, width, and height to be valid
     68        return (float) $product->get_length() > 0 &&
    6569            (float) $product->get_width() > 0 &&
    6670            (float) $product->get_height() > 0;
     
    145149        $cost = ($pricing_type === 'flat_rate') ? (float) $this->get_option('flat_rate_cost') : $this->get_dynamic_shipping_rate($package);
    146150
     151        $margin = ($pricing_type === 'margin_rate') ? (float) $this->get_option('margin_rate') : $this->get_dynamic_shipping_rate($package);
     152        if ($margin) {
     153            $cost = $cost * $margin;
     154        }
     155
    147156        if (WC()->cart->get_cart_contents_total() >= $this->get_option('free_shipping_threshold')) {
    148157            $cost = 0;
     
    164173            $product = $item['data'];
    165174            $quantity = $item['quantity'];
     175           
     176            // Use default weight if missing
     177            $weight = (float) $product->get_weight();
     178            if ($weight <= 0) {
     179                $weight = 1.0; // Default 1kg
     180                // Set flag to show notice
     181                WC()->session->set('shiperman_default_weight_applied', true);
     182            }
    166183
    167184            for ($i = 0; $i < $quantity; $i++) {
     
    170187                    'name'   => $product->get_name(),
    171188                    'price'  => (float) $product->get_price(),
    172                     'weight' => (float) $product->get_weight(),
     189                    'weight' => $weight, // Use calculated weight
    173190                    'length' => (float) $product->get_length(),
    174191                    'width'  => (float) $product->get_width(),
     
    206223    public function process_admin_options()
    207224    {
    208         $missing_info = $this->get_products_missing_shipping_info();
     225        /*$missing_info = $this->get_products_missing_shipping_info();
    209226        if (!empty($missing_info)) {
    210227            // Force-disable and show message
     
    214231            add_action('admin_notices', function () {
    215232                echo '<div class="notice notice-error is-dismissible">';
    216                 echo '<p>' . esc_html__('Shiperman Shipping cannot be enabled until all physical products have valid shipping data.', 'shiperman-for-woocommerce') . '</p>';
     233                echo '<p>' . esc_html__('Shiperman Shipping cannot be enabled until all physical products have valid length, width, and height. Weight will use default 1kg if not set.', 'shiperman-for-woocommerce') . '</p>';
    217234                echo '<p><a href="' . esc_url(admin_url('admin.php?page=shiperman_validate_shop_tools')) . '" class="button button-primary">';
    218235                echo esc_html__('Validate Products Now', 'shiperman-for-woocommerce');
     
    223240
    224241            return; // Don't save options
    225         }
     242        }*/
    226243
    227244        parent::process_admin_options();
    228245    }
     246
    229247}
  • shiperman-for-woocommerce/trunk/readme.txt

    r3281024 r3343366  
    66Tested up to: 6.8 
    77Requires PHP: 7.4 
    8 Stable tag: 1.4.0 
     8Stable tag: 1.4.1 
    99License: GPLv2 or later 
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html 
     
    6868== Changelog ==
    6969
     70= 1.4.1 =
     71* Fixed Product edit issue.
     72* Automatically assign a default weight of 1 kg when a product without defined weight is added to the cart.
     73* Added admin notice on WooCommerce Orders page regarding default shipment weight.
     74
    7075= 1.4.0 =
    7176* Added "Settings" & "Set Pricing" Menus For Easy Navigation.
     
    114119== Upgrade Notice ==
    115120
     121= 1.4.1 =
     122* Mandatory update.
     123
    116124= 1.4.0 = 
    117125* Mandatory update.
  • shiperman-for-woocommerce/trunk/shiperman-for-woocommerce.php

    r3281024 r3343366  
    33Plugin Name: Shiperman for WooCommerce
    44Description: Integrates Shiperman shipping services into WooCommerce with real-time rate calculations and flexible rate configurations.
    5 Version: 1.3.2
     5Version: 1.4.1
    66Author: Shiperman
    77Author URI: https://shiperman.com
Note: See TracChangeset for help on using the changeset viewer.