Created
May 10, 2023 23:48
-
-
Save barryhughes/0081fc4e62842693fee998dcc9f27cc5 to your computer and use it in GitHub Desktop.
A possible alternative to the initial solution in WooCommerce PR#37847 (relates to this comment: https://github.com/woocommerce/woocommerce/pull/37847#issuecomment-1542940612)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/plugins/woocommerce/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php b/plugins/woocommerce/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php | |
index 4b140a814f..5719a8a12b 100644 | |
--- a/plugins/woocommerce/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php | |
+++ b/plugins/woocommerce/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php | |
@@ -177,8 +177,16 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { | |
// Also handles BW compatibility when slugs were used instead of ids. | |
$shipping_class_term = get_term_by( 'slug', $shipping_class, 'product_shipping_class' ); | |
$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', '' ); | |
- | |
- if ( '' === $class_cost_string ) { | |
+ $no_class_cost = 0 === strlen( $class_cost_string ); | |
+ | |
+ if ( $no_class_cost && 'class' === $this->type ) { | |
+ // If we are calculating per each individual shipping class, but one of the products belongs to a class | |
+ // for which a cost has not been defined, then we cannot supply a shipping rate. | |
+ $has_costs = false; | |
+ break; | |
+ } elseif ( $no_class_cost ) { | |
+ // Otherwise, if we do not have a class cost but we are intending to use the highest available rate, | |
+ // we should simply skip this product. | |
continue; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment