Support » Plugin: WooCommerce » need script to add package weight to total cart weight in woocommerce

Viewing 4 replies - 1 through 4 (of 4 total)
  • Not had the chance to test but can you try:

    Delete line 12

    Delete from line 13: $shipping_class == ‘shipping-class-slug’ &&

    So line 13 reads: if (!empty($original_weight)){

    Thread Starter stefansic

    (@stefansic)

    Thank you, but it does not work, now, it looks like this:

    add_action( ‘woocommerce_before_calculate_totals’, ‘rscott_add_custom_weight’, 10, 1);
    function rscott_add_custom_weight( $cart_object ) {
    if ( (is_admin() && ! defined( ‘DOING_AJAX’ ) ) || $cart_object->is_empty() )
    return;
    if ( did_action( ‘woocommerce_before_calculate_totals’ ) >= 2 )
    return;
    $additionalweight = 2000;
    foreach ( $cart_object->get_cart() as $cart_item ) {

    if (!empty($original_weight)){
    //get the current weight
    $original_weight = $cart_item[‘data’]->get_weight();
    // calculate new weight
    $new_weight = $original_weight + $additionalweight;
    // Set new weight
    $cart_item[‘data’]->set_weight( $new_weight );
    }
    }
    }

    Plugin Support mouli a11n

    (@mouli)

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Plugin Support gabrielfuentes

    (@gabrielfuentes)

    We’ve not seen any activity on this thread for a while, so I’m marking this thread as resolved.

    Hopefully, you were able to find a solution to your problem! If you have further questions, please feel free to open a new topic.

    Cheers! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘need script to add package weight to total cart weight in woocommerce’ is closed to new replies.