diff --git a/changelog.txt b/changelog.txt index 76ac4d2a5c..cf4b89995f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,7 @@ *** Changelog *** = 9.5.0 - xxxx-xx-xx = +* Dev - Implements WooCommerce constants for the product types. * Fix - Fixes the listing of payment methods on the classic checkout when the Optimized Checkout is enabled. * Fix - Fixes the availability of WeChat Pay when the Optimized Checkout is enabled on the block checkout. Removes it from the classic/shortcode checkout to avoid issues. * Dev - Renames all references to "Smart Checkout" and "Single Payment Element" (and "SPE") to "Optimized Checkout" (and "OC"), following the feature rebranding. diff --git a/includes/payment-methods/class-wc-stripe-express-checkout-ajax-handler.php b/includes/payment-methods/class-wc-stripe-express-checkout-ajax-handler.php index 20e1890984..1ca106511a 100644 --- a/includes/payment-methods/class-wc-stripe-express-checkout-ajax-handler.php +++ b/includes/payment-methods/class-wc-stripe-express-checkout-ajax-handler.php @@ -1,4 +1,7 @@ cart->empty_cart(); - if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { + if ( ( ProductType::VARIABLE === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); $data_store = WC_Data_Store::load( 'product' ); @@ -216,7 +219,7 @@ public function ajax_get_selected_product_data() { throw new Exception( sprintf( __( 'Product with the ID (%1$s) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) ); } - if ( in_array( $product->get_type(), [ 'variable', 'variable-subscription' ], true ) && isset( $_POST['attributes'] ) ) { + if ( in_array( $product->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) && isset( $_POST['attributes'] ) ) { $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); $data_store = WC_Data_Store::load( 'product' ); diff --git a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php index 087d3125be..d60a537800 100644 --- a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php +++ b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php @@ -1,5 +1,7 @@ get_type(), [ 'variable', 'variable-subscription' ], true ) ) { + if ( in_array( $product->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) ) { $variation_attributes = $product->get_variation_attributes(); $attributes = []; @@ -391,9 +393,9 @@ public function supported_product_types() { return apply_filters( 'wc_stripe_payment_request_supported_types', [ - 'simple', - 'variable', - 'variation', + ProductType::SIMPLE, + ProductType::VARIABLE, + ProductType::VARIATION, 'subscription', 'variable-subscription', 'subscription_variation', @@ -656,7 +658,7 @@ public function should_show_express_checkout_button() { return false; } - if ( $is_product && $product && in_array( $product->get_type(), [ 'variable', 'variable-subscription' ], true ) ) { + if ( $is_product && $product && in_array( $product->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) ) { $stock_availability = array_column( $product->get_available_variations(), 'is_in_stock' ); // Don't show if all product variations are out-of-stock. if ( ! in_array( true, $stock_availability, true ) ) { diff --git a/includes/payment-methods/class-wc-stripe-payment-request.php b/includes/payment-methods/class-wc-stripe-payment-request.php index 21fd8d8540..6e0cbf664d 100644 --- a/includes/payment-methods/class-wc-stripe-payment-request.php +++ b/includes/payment-methods/class-wc-stripe-payment-request.php @@ -8,6 +8,8 @@ * @since 4.0.0 */ +use Automattic\WooCommerce\Enums\ProductType; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -398,7 +400,7 @@ public function get_product_data() { $product = $this->get_product(); $variation_id = 0; - if ( in_array( $product->get_type(), [ 'variable', 'variable-subscription' ], true ) ) { + if ( in_array( $product->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) ) { $variation_attributes = $product->get_variation_attributes(); $attributes = []; @@ -596,9 +598,9 @@ public function supported_product_types() { return apply_filters( 'wc_stripe_payment_request_supported_types', [ - 'simple', - 'variable', - 'variation', + ProductType::SIMPLE, + ProductType::VARIABLE, + ProductType::VARIATION, 'subscription', 'variable-subscription', 'subscription_variation', @@ -1027,7 +1029,7 @@ public function should_show_payment_request_button() { return false; } - if ( $this->is_product() && in_array( $this->get_product()->get_type(), [ 'variable', 'variable-subscription' ], true ) ) { + if ( $this->is_product() && in_array( $this->get_product()->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) ) { $stock_availability = array_column( $this->get_product()->get_available_variations(), 'is_in_stock' ); // Don't show if all product variations are out-of-stock. if ( ! in_array( true, $stock_availability, true ) ) { @@ -1372,7 +1374,7 @@ public function ajax_get_selected_product_data() { throw new Exception( sprintf( __( 'Product with the ID (%1$s) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) ); } - if ( in_array( $product->get_type(), [ 'variable', 'variable-subscription' ], true ) && isset( $_POST['attributes'] ) ) { + if ( in_array( $product->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) && isset( $_POST['attributes'] ) ) { $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); $data_store = WC_Data_Store::load( 'product' ); @@ -1479,7 +1481,7 @@ public function ajax_add_to_cart() { // First empty the cart to prevent wrong calculation. WC()->cart->empty_cart(); - if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { + if ( ( ProductType::VARIABLE === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); $data_store = WC_Data_Store::load( 'product' ); diff --git a/readme.txt b/readme.txt index d63d8a283a..ccf94338fb 100644 --- a/readme.txt +++ b/readme.txt @@ -165,6 +165,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o **Internal Changes and Upcoming Features** +* Dev - Implements WooCommerce constants for the product types. * Feature - Work to support Optimized Checkout * Feature - Work to support Amazon Pay * Dev - Splits the code coverage GitHub Actions Workflow into two separate actions