Skip to content
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

Show PRB on cart and product page when there are required custom checkout fields #3036

Merged
merged 4 commits into from
Apr 4, 2024
Merged
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 ***

= 8.1.1 - xxxx-xx-xx =
* Fix - Do not hide PRB on cart and product page when there are required custom checkout fields.
* Fix - Issue with subscription renewal when the `start_date` of the mandate is set in the past.

= 8.1.0 - 2024-03-28 =
Expand Down
58 changes: 0 additions & 58 deletions includes/payment-methods/class-wc-stripe-payment-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ If you get stuck, you can ask for help in the Plugin Forum.
== Changelog ==

= 8.1.1 - xxxx-xx-xx =
* Fix - Do not hide PRB on cart and product page when there are required custom checkout fields.
* Fix - Issue with subscription renewal when the `start_date` of the mandate is set in the past.

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).
Loading