Skip to content

Commit 0241caf

Browse files
wjrosadaledupreez
andauthored
Implementing product type constants (#4474)
* Implementing product type constants * Changelog and readme entries * Update changelog.txt Co-authored-by: daledupreez <dale.du.preez@automattic.com> * Update readme entry --------- Co-authored-by: daledupreez <dale.du.preez@automattic.com>
1 parent 8d6a6eb commit 0241caf

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.7.0 - xxxx-xx-xx =
4+
* Dev - Use product type constants that were added in WooCommerce 9.7
45
* Dev - Removes the inclusion of the deprecated WC_Stripe_Order class
56
* Add - Introduces a new banner to promote the Optimized Checkout feature in the Stripe settings page for versions 9.8 and above
67
* Add - Introduces a new inbox note to promote the Optimized Checkout feature on version 9.8 and later

includes/payment-methods/class-wc-stripe-express-checkout-ajax-handler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
use Automattic\WooCommerce\Enums\ProductType;
4+
25
if ( ! defined( 'ABSPATH' ) ) {
36
exit;
47
}
@@ -92,7 +95,7 @@ public function ajax_add_to_cart() {
9295
// First empty the cart to prevent wrong calculation.
9396
WC()->cart->empty_cart();
9497

95-
if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {
98+
if ( ( ProductType::VARIABLE === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {
9699
$attributes = wc_clean( wp_unslash( $_POST['attributes'] ) );
97100

98101
$data_store = WC_Data_Store::load( 'product' );
@@ -232,7 +235,7 @@ public function ajax_get_selected_product_data() {
232235
throw new Exception( sprintf( __( 'Product with the ID (%1$s) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) );
233236
}
234237

235-
if ( in_array( $product->get_type(), [ 'variable', 'variable-subscription' ], true ) && isset( $_POST['attributes'] ) ) {
238+
if ( in_array( $product->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) && isset( $_POST['attributes'] ) ) {
236239
$attributes = wc_clean( wp_unslash( $_POST['attributes'] ) );
237240

238241
$data_store = WC_Data_Store::load( 'product' );

includes/payment-methods/class-wc-stripe-express-checkout-helper.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Automattic\WooCommerce\Enums\ProductType;
4+
35
if ( ! defined( 'ABSPATH' ) ) {
46
exit;
57
}
@@ -225,7 +227,7 @@ public function get_product_data() {
225227
return false;
226228
}
227229

228-
if ( in_array( $product->get_type(), [ 'variable', 'variable-subscription' ], true ) ) {
230+
if ( in_array( $product->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) ) {
229231
$variation_attributes = $product->get_variation_attributes();
230232
$attributes = [];
231233

@@ -424,9 +426,9 @@ public function supported_product_types() {
424426
return apply_filters(
425427
'wc_stripe_payment_request_supported_types',
426428
[
427-
'simple',
428-
'variable',
429-
'variation',
429+
ProductType::SIMPLE,
430+
ProductType::VARIABLE,
431+
ProductType::VARIATION,
430432
'subscription',
431433
'variable-subscription',
432434
'subscription_variation',
@@ -689,7 +691,7 @@ public function should_show_express_checkout_button() {
689691
return false;
690692
}
691693

692-
if ( $is_product && $product && in_array( $product->get_type(), [ 'variable', 'variable-subscription' ], true ) ) {
694+
if ( $is_product && $product && in_array( $product->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) ) {
693695
$stock_availability = array_column( $product->get_available_variations(), 'is_in_stock' );
694696
// Don't show if all product variations are out-of-stock.
695697
if ( ! in_array( true, $stock_availability, true ) ) {

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 9.7.0 - xxxx-xx-xx =
114+
* Dev - Use product type constants that were added in WooCommerce 9.7
114115
* Dev - Removes the inclusion of the deprecated WC_Stripe_Order class
115116
* Add - Introduces a new banner to promote the Optimized Checkout feature in the Stripe settings page for versions 9.8 and above
116117
* Add - Introduces a new inbox note to promote the Optimized Checkout feature on version 9.8 and later

0 commit comments

Comments
 (0)