Skip to content

Implementing product type constants #4474

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
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 @@ -92,7 +95,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 @@ -232,7 +235,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 @@ -408,9 +410,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 @@ -673,7 +675,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
Loading