From 725f6b4c964d04fa9ea8cad8e094d16e50822f7c Mon Sep 17 00:00:00 2001 From: Mayisha Date: Tue, 2 Apr 2024 22:19:40 +0600 Subject: [PATCH 1/2] do not hide PRB on cart and product page when there are required custom checkout fields --- .../class-wc-stripe-payment-request.php | 58 ------------------- 1 file changed, 58 deletions(-) diff --git a/includes/payment-methods/class-wc-stripe-payment-request.php b/includes/payment-methods/class-wc-stripe-payment-request.php index cb40cf6b57..6358da66ff 100644 --- a/includes/payment-methods/class-wc-stripe-payment-request.php +++ b/includes/payment-methods/class-wc-stripe-payment-request.php @@ -976,11 +976,6 @@ public function should_show_payment_request_button() { return false; } - // Don't show on cart if there are required checkout fields. - if ( is_cart() && $this->has_required_checkout_fields() ) { - return false; - } - // Don't show on checkout if disabled. if ( is_checkout() && ! $this->should_show_prb_on_checkout_page() ) { return false; @@ -991,11 +986,6 @@ public function should_show_payment_request_button() { return false; } - // Don't show on product if there are required checkout fields. - if ( $this->is_product() && $this->has_required_checkout_fields() ) { - return false; - } - // Don't show if product on current page is not supported. if ( $this->is_product() && ! $this->is_product_supported( $this->get_product() ) ) { return false; @@ -1070,54 +1060,6 @@ public function should_show_prb_on_product_pages() { ); } - /** - * Returns true if the checkout has any required fields other than the default ones, false otherwise. - * to not be empty. - * - * @since 8.0.0 - * - * @return boolean - */ - public function has_required_checkout_fields() { - // Default WooCommerce Core required fields for billing and shipping. - $default_required_fields = [ - 'billing_first_name', - 'billing_last_name', - 'billing_country', - 'billing_address_1', - 'billing_city', - 'billing_state', - 'billing_postcode', - 'billing_phone', - 'billing_email', - 'shipping_first_name', - 'shipping_last_name', - 'shipping_country', - 'shipping_address_1', - 'shipping_city', - 'shipping_state', - 'shipping_postcode', - ]; - - $fields = WC()->checkout()->get_checkout_fields(); - $fields = array_merge( - $fields['billing'] ?? [], - $fields['shipping'] ?? [], - $fields['order'] ?? [], - $fields['account'] ?? [] - ); - - foreach ( $fields as $field_key => $field_data ) { - if ( false === array_search( $field_key, $default_required_fields, true ) ) { - if ( isset( $field_data['required'] ) && true === $field_data['required'] ) { - return true; - } - } - } - - return false; - } - /** * Returns true if a the provided product is supported, false otherwise. * From 65a95a06cbb514db522d3d3f818adf92d48348e2 Mon Sep 17 00:00:00 2001 From: Mayisha Date: Tue, 2 Apr 2024 22:19:48 +0600 Subject: [PATCH 2/2] add changelog entry --- changelog.txt | 3 +++ readme.txt | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 00037732a4..3726557db2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,9 @@ = 8.2.0 - xxxx-xx-xx = += 8.1.1 - xxxx-xx-xx = +* Fix - Do not hide PRB on cart and product page when there are required custom checkout fields. + = 8.1.0 - 2024-03-28 = * Add - Include Stripe account details to the settings page. * Add - Include Stripe API version in logs. diff --git a/readme.txt b/readme.txt index 69816ed966..4ee895d206 100644 --- a/readme.txt +++ b/readme.txt @@ -128,6 +128,7 @@ If you get stuck, you can ask for help in the Plugin Forum. == Changelog == -= 8.2.0 - xxxx-xx-xx = += 8.1.1 - xxxx-xx-xx = +* Fix - Do not hide PRB on cart and product page when there are required custom checkout fields. [See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).