• I created a code that allows me to calculate the longest or widest or tallest object. I need this to determine that the product does not exceed certain dimensions that the courier imposes for the various shipping classes. In this way I managed to solve the problem but with each update there is a risk that the file will be overwritten and therefore it will not work. Can you insert a hook or another way to modify these functions from the child theme? Thank you
    file class-conditional-shipping-filters.php
    code:
    /**
    * Calculate cart height
    */
    private static function calculate_package_height($package) {
    //$total = 0;
    $highestValue = 0;

    foreach ( $package[‘contents’] as $key => $data ) {
    $product = $data[‘data’];

    if ( ! $product->needs_shipping() || ! $product->has_dimensions() ) {
    continue;
    }

    $item_height = $product->get_height();

    if ( $item_height ) {
    if($item_height > $highestValue){
    $highestValue = $item_height;
    }
    //$total += floatval( $item_height ) * $data[‘quantity’];
    }
    }

    return $highestValue;
    //return $total;
    }

    /**
    * Calculate cart length
    */
    private static function calculate_package_length($package) {
    //$total = 0;
    $highestValue = 0;

    foreach ( $package[‘contents’] as $key => $data ) {
    $product = $data[‘data’];

    if ( ! $product->needs_shipping() || ! $product->has_dimensions() ) {
    continue;
    }

    $item_length = $product->get_length();

    if ( $item_length ) {
    if($item_length > $highestValue){
    $highestValue = $item_length;
    }
    //$total += floatval( $item_length ) * $data[‘quantity’];
    }
    }

    return $highestValue;
    //return $total;
    }

    /**
    * Calculate cart width
    */
    private static function calculate_package_width($package) {
    //$total = 0;
    $highestValue = 0;

    foreach ( $package[‘contents’] as $key => $data ) {
    $product = $data[‘data’];

    if ( ! $product->needs_shipping() || ! $product->has_dimensions() ) {
    continue;
    }

    $item_width = $product->get_width();

    if ( $item_width ) {
    if($item_width > $highestValue){
    $highestValue = $item_width;
    }
    //$total += floatval( $item_width ) * $data[‘quantity’];
    }
    }

    return $highestValue;
    //return $total;
    }

  • The topic ‘Change the size calculation method’ is closed to new replies.