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