• Resolved fewturewebdesign

    (@fewturewebdesign)


    Here is a detailed video of the issue:

    https://www.loom.com/share/a90aa8907a5b4100965ed38ff5e526bd?sid=f5387c5a-9557-4633-ade6-826642716385

    We are using a custom product configurator and therefore add product weights dynamically. The weight is shown correctly and therefore is added the right way. But unfortunately, after changing the postal code, the shipping cost is wrong. Even after changing it back to the original postal code.

    We store our weight in $cart_item['new_weight']
    And we add like this while adding it to the cart:

    $cart_item['data']->set_weight($cart_item['new_weight']);

    It works perfect, just not on the checkout page unfortunately.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Dan

    (@dangoodman)

    It might be related to the caching. Changing the product weight does not automatically reset the shipping cache. You can temporarily disable it with WooCommerce > Settings > Shipping > Shipping options > Debug.

    Another point to check is what weight WBS “sees”. Create a rule with Weight Rate: ‘charge €1 for each 0kg over 0kg’. It will show the total weight it gets as its price.

    • This reply was modified 1 year, 6 months ago by Dan.
    Thread Starter fewturewebdesign

    (@fewturewebdesign)

    Hi Dan,

    thank you for the fast reply!
    We have figured out the issue, and we think, that it is related to the way, in which the product weight is calculated.

    In the PackageConverter.php we have changed line 143, where it gets the product weight directly, by calling $product->get_weight().

    Since our custom weight is stored as a new variable in the cart items only, we need the cart item weight. Therefore we changed it to $_item['new_weight'].

    Would the use of cart items to retrieve the weight be something that could be considered changing in an update? Maybe we did miss something.


    Since cart items normally have the same weight as the product itself, functionality would still work for normal use cases, and additionally, for use cases, in which the cart item is modified dynamically. It makes the use of ‘quantity’ obsolete as well, since the weight is multiplied by quantity of products already.

    Best regards,
    Walid

    Plugin Author Dan

    (@dangoodman)

    Hi Walid,

    Thank you for the update.

    I think the right way to solve this is to provide the custom weight in the “standard” way, i.e., how WooCommerce does that. In this case, not only WBS but also all other plugins will be happy.

    Do you have a reason for not doing so?

    Thread Starter fewturewebdesign

    (@fewturewebdesign)

    Hi Dan,

    since we are offering highly customizable and custom products, we can not set a static weight for our products. Also, the same WooCommerce product, in our case a steelbeam, could be configured in several different ways, which results in different weights for the same ‘product’.

    That’s the main reason, why we need to set the weight per cart item, and not per product. Does that make sense?

    Would there be a possibility, to include a setting for a ‘custom class’ to retrieve the weight for? Or is our use case to rare. Maybe you could include such functionality hidden under some kind of ‘developer/expert features’.
    That way, we do not need to change the related code for each update.

    Looking forward to your answer and thank you for your support!

    Best regards,
    Walid

    Plugin Author Dan

    (@dangoodman)

    WooCommerce product variations can have different weights for a single product. Did you check them?

    If that is not dynamic enough for your case, you can create WC_Product or WC_Product_Variation class instances on the fly to substitute them into the cart.

    Another option is to override the WC_Product->get_weight() hook to provide the custom weight.

    Do you think neither of these works for you?

    Hello, I have the same issue. Any luck solving this problem yet ?
    I tried with displaying and saving cart weight but no luck – When I change region, the cost resets to lowest rate (As if the cart weighted 0 kgs). Here’s what I tried to do:

    // Display the cart item weight in cart and checkout pages
    add_filter( 'woocommerce_get_item_data', 'display_custom_item_data', 10, 2 );
    function display_custom_item_data( $cart_item_data, $cart_item ) {
    if ( $cart_item['data']->get_weight() > 0 ){
    $cart_item_data[] = array(
    'name' => __( 'Weight subtotal', 'vnsscustom' ),
    'value' => ( $cart_item['quantity'] * $cart_item['data']->get_weight() ) . ' ' . get_option('woocommerce_weight_unit').' ['.$cart_item['quantity'].' * '.$cart_item['data']->get_weight().']'
    );
    }
    return $cart_item_data;
    }

    // Save and Display the order item weight (everywhere)
    add_action( 'woocommerce_checkout_create_order_line_item', 'display_order_item_data', 20, 4 );
    function display_order_item_data( $item, $cart_item_key, $values, $order ) {
    if ( $values['data']->get_weight() > 0 ){
    $item->update_meta_data( __( 'Weight subtotal', 'vnsscustom' ), ( $values['quantity'] * $values['data']->get_weight() ) . ' ' . get_option('woocommerce_weight_unit') );
    }

    }

    • This reply was modified 1 year, 5 months ago by wolleamore.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Shipping Price resets after postal change’ is closed to new replies.