diff --git a/plugins/woocommerce/changelog/issue-33924-type-safety b/plugins/woocommerce/changelog/issue-33924-type-safety new file mode 100644 index 00000000000..37173420fd7 --- /dev/null +++ b/plugins/woocommerce/changelog/issue-33924-type-safety @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Add type safety while getting product price diff --git a/plugins/woocommerce/includes/wc-product-functions.php b/plugins/woocommerce/includes/wc-product-functions.php index 0b692aa4e3f..132de94d689 100644 --- a/plugins/woocommerce/includes/wc-product-functions.php +++ b/plugins/woocommerce/includes/wc-product-functions.php @@ -987,7 +987,7 @@ function wc_get_price_including_tax( $product, $args = array() ) { ) ); - $price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : $product->get_price(); + $price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : (float) $product->get_price(); $qty = '' !== $args['qty'] ? max( 0.0, (float) $args['qty'] ) : 1; if ( '' === $price ) { @@ -1071,7 +1071,7 @@ function wc_get_price_excluding_tax( $product, $args = array() ) { ) ); - $price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : $product->get_price(); + $price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : (float) $product->get_price(); $qty = '' !== $args['qty'] ? max( 0.0, (float) $args['qty'] ) : 1; if ( '' === $price ) {