• Hi there.

    I ran into another issue, sorry…

    If the plugin took its dimensions and weight from cart data instead of product data, it would be more-compatible with Woocommerce and the various plugins that might need to alter dimensions and weight (such as if someone was wanting to order 10 feet if steel beam, 12 cu yards of dirt, 2 tons of gravel, etc…)

    For example: 

    accessing woocommerce_get_item_data to grab

    $cart_item['data']->get_weight()

    in WC_Shipping_RLC.php it appears to instead be reaching back to product data for this.

    public function add_package_items_to_request($package, &$request)
            {
                $contents = $package['contents'];
    
                foreach ( $contents as $key => $item )
                {
                    $id = intval($item['variation_id'])?$item['variation_id']:$item['product_id'];
                    $_pf = new WC_Product_Factory();
                    $product = $_pf->get_product($id);
    
                    $request['items'][$key] = array(
                        'product_id' => $item['product_id'],
                        'variation_id' => $item['variation_id'],
                        'quantity' => $item['quantity'],
                        'origin' => array_key_exists('origin', $package)?$package['origin']:null,
                        'class' => wc_rlc_get_item_shipping_class($id, $package, $this),
                        'weight' => $product->get_weight(),
                        'is_hazmat' => wc_rlc_is_product_hazmat($id),
                        'length' => $product->get_length(),
                        'width' => $product->get_width(),
                        'height'=> $product->get_height()
                    );
                }
            }

    Knowing the plugin better than I do, is there a quick and simple hook you could recommend for this? I would say that this sort of enhancement as a permanent change could make the plugin play better with others.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Sorry for the new issue. I wish I could help you, but my knowledge of the plugin is minimal and I have not done any backend enhancements to it. Maybe there is a Woo app coder that could possibly help? Best of luck!

    Thread Starter industrialweb

    (@industrialweb)

    Well, I’m in the support area for a plugin that was written for Woo. Hopefully they can help out. It has been nearly a year since the last update though. I suppose if the plugin is never going to receive updates from here there is no real harm in me making direct updates.

    Yeah, hopefully the support area can help out. But if it has been that long since the last update then it is likely abandoned.

    Thread Starter industrialweb

    (@industrialweb)

    I have found out from them that there will be an update around Aug 8.

    That is fortunate for stability and compatibility… unfortunate for my chance to direct edit.

    Around 1026 I found and changed two lines (not recommended).

    public function add_package_items_to_request($package, &$request)
            {
                $contents = $package['contents'];
    
                foreach ( $contents as $key => $item )
                {
                    $id = intval($item['variation_id'])?$item['variation_id']:$item['product_id'];
                    $_pf = new WC_Product_Factory();
                    $product = $_pf->get_product($id);
    
                    $request['items'][$key] = array(
                        'product_id' => $item['product_id'],
                        'variation_id' => $item['variation_id'],
                        'quantity' => $item['quantity'],
                        'origin' => array_key_exists('origin', $package)?$package['origin']:null,
                        'class' => wc_rlc_get_item_shipping_class($id, $package, $this),
                        // Myke Editing to get proper weight and size from cart variables.
    		   //'weight' => $product->get_weight(),
    					'weight' =>$item['data']->get_weight(),
                        'is_hazmat' => wc_rlc_is_product_hazmat($id),
                        //'length' => $product->get_length(),
    					'length' => $item['pricing_item_meta_data']['length'] ? $item['pricing_item_meta_data']['length'] : $product->get_length(),
                        'width' => $item['data']->get_width(),
                        'height'=> $item['data']->get_height()
    		    // END Myke Editing to get proper weight and size from cart variables.
                    );
                }
            }

    If I could re-create these edits as a hook/filter in functions.php I’d probably be set.

    Thread Starter industrialweb

    (@industrialweb)

    Unfortunately, the function to hook/filter is protected within a class.

    Double-unfortunately you can’t even override the variables, because their function reaches back to the base product properties in the DB rather than the weights and dimensions available in the cart data.

    I really hope they make their functions hookable/filterable in the next version, or at least this one. I also hope they decide to use cart data instead of reaching all the way back to product data.

    The only solution for me is modifying the plugin and renaming it – and hoping I can apply my fixes to the next version.

    For now, here are my mods made to make shipping work with measurements from the cart.

    public function add_package_items_to_request($package, &$request)
            {
                $contents = $package['contents'];
    
                foreach ( $contents as $key => $item )
                {
                    $id = intval($item['variation_id'])?$item['variation_id']:$item['product_id'];
                    $_pf = new WC_Product_Factory();
                    $product = $_pf->get_product($id);
    
                    $request['items'][$key] = array(
                        'product_id' => $item['product_id'],
                        'variation_id' => $item['variation_id'],
                        'quantity' => $item['quantity'],
                        'origin' => array_key_exists('origin', $package)?$package['origin']:null,
                        'class' => wc_rlc_get_item_shipping_class($id, $package, $this),
                      // Editing to get proper weight and size from cart variables.
    					//'weight' => $product->get_weight(),
    					'weight' => $item['data']->get_weight(),
                        'is_hazmat' => wc_rlc_is_product_hazmat($id),
                        //'height'=> $product->get_height(), (... etc...)
    					'length' => $item['pricing_item_meta_data']['length'] ? $item['pricing_item_meta_data']['length'] : $product->get_length(),
                        'width' => $item['pricing_item_meta_data']['width'] ? $item['pricing_item_meta_data']['width'] : $product->get_width(),
                        'height'=> $item['pricing_item_meta_data']['height'] ? $item['pricing_item_meta_data']['height'] : $product->get_height()
    		// END Editing to get proper weight and size from cart variables.
                    );
                }
            }

    Wow, an unfortunate case to having to work around and hope for the best with the future release. Agree, it would be optimal if they made it hook friendly…and use cart data! Best of luck!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Calculated Lengths and Weights not reaching shipping calculations’ is closed to new replies.