Skip to content

Using the new product type constants #4303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use Automattic\WooCommerce\Enums\ProductType;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand Down Expand Up @@ -91,7 +94,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' );
Expand Down Expand Up @@ -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' );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Automattic\WooCommerce\Enums\ProductType;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand Down Expand Up @@ -225,7 +227,7 @@ public function get_product_data() {
return false;
}

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 = [];

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 ) ) {
Expand Down
16 changes: 9 additions & 7 deletions includes/payment-methods/class-wc-stripe-payment-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @since 4.0.0
*/

use Automattic\WooCommerce\Enums\ProductType;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand Down Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -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' );
Expand Down Expand Up @@ -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' );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading