| @@ 148-168 (lines=21) @@ | ||
| 145 | $found_shipping_classes = $this->find_shipping_classes( $package ); |
|
| 146 | $highest_class_cost = 0; |
|
| 147 | ||
| 148 | foreach ( $found_shipping_classes as $shipping_class => $products ) { |
|
| 149 | // Also handles BW compatibility when slugs were used instead of ids |
|
| 150 | $shipping_class_term = get_term_by( 'slug', $shipping_class, 'product_shipping_class' ); |
|
| 151 | $class_cost_string = $shipping_class_term && $shipping_class_term->term_id ? $this->get_option( 'class_cost_' . $shipping_class_term->term_id, $this->get_option( 'class_cost_' . $shipping_class, '' ) ) : $this->get_option( 'no_class_cost', '' ); |
|
| 152 | ||
| 153 | if ( $class_cost_string === '' ) { |
|
| 154 | continue; |
|
| 155 | } |
|
| 156 | ||
| 157 | $has_costs = true; |
|
| 158 | $class_cost = $this->evaluate_cost( $class_cost_string, array( |
|
| 159 | 'qty' => array_sum( wp_list_pluck( $products, 'quantity' ) ), |
|
| 160 | 'cost' => array_sum( wp_list_pluck( $products, 'line_total' ) ) |
|
| 161 | ) ); |
|
| 162 | ||
| 163 | if ( $this->type === 'class' ) { |
|
| 164 | $rate['cost'] += $class_cost; |
|
| 165 | } else { |
|
| 166 | $highest_class_cost = $class_cost > $highest_class_cost ? $class_cost : $highest_class_cost; |
|
| 167 | } |
|
| 168 | } |
|
| 169 | ||
| 170 | if ( $this->type === 'order' && $highest_class_cost ) { |
|
| 171 | $rate['cost'] += $highest_class_cost; |
|
| @@ 177-197 (lines=21) @@ | ||
| 174 | $found_shipping_classes = $this->find_shipping_classes( $package ); |
|
| 175 | $highest_class_cost = 0; |
|
| 176 | ||
| 177 | foreach ( $found_shipping_classes as $shipping_class => $products ) { |
|
| 178 | // Also handles BW compatibility when slugs were used instead of ids |
|
| 179 | $shipping_class_term = get_term_by( 'slug', $shipping_class, 'product_shipping_class' ); |
|
| 180 | $class_cost_string = $shipping_class_term && $shipping_class_term->term_id ? $this->get_option( 'class_cost_' . $shipping_class_term->term_id, $this->get_option( 'class_cost_' . $shipping_class, '' ) ) : $this->get_option( 'no_class_cost', '' ); |
|
| 181 | ||
| 182 | if ( $class_cost_string === '' ) { |
|
| 183 | continue; |
|
| 184 | } |
|
| 185 | ||
| 186 | $has_costs = true; |
|
| 187 | $class_cost = $this->evaluate_cost( $class_cost_string, array( |
|
| 188 | 'qty' => array_sum( wp_list_pluck( $products, 'quantity' ) ), |
|
| 189 | 'cost' => array_sum( wp_list_pluck( $products, 'line_total' ) ) |
|
| 190 | ) ); |
|
| 191 | ||
| 192 | if ( $this->type === 'class' ) { |
|
| 193 | $rate['cost'] += $class_cost; |
|
| 194 | } else { |
|
| 195 | $highest_class_cost = $class_cost > $highest_class_cost ? $class_cost : $highest_class_cost; |
|
| 196 | } |
|
| 197 | } |
|
| 198 | ||
| 199 | if ( $this->type === 'order' && $highest_class_cost ) { |
|
| 200 | $rate['cost'] += $highest_class_cost; |
|