• Can you make the below code to work only for any specific addons product weight in cart. Thanks

    add_action( ‘woocommerce_before_calculate_totals’, ‘add_custom_weight’, 10, 1 );
    function add_custom_weight( $cart ) {
    if ( is_admin() && ! defined( ‘DOING_AJAX’ ) )
    return;

    if ( did_action( ‘woocommerce_before_calculate_totals’ ) >= 2 )
    return;

    foreach ( $cart->get_cart() as $cart_item ) {
    //very simplified example – every item in cart will be 100 kg
    $cart_item[‘data’]->set_weight( 100 );
    }
    // print_r( $cart->get_cart_contents_weight() ); // Only for testing (not on checkout page)
    }

    The page I need help with: [log in to see the link]

  • The topic ‘custom Weight for specific product for woocommerce TM EPO’ is closed to new replies.