Skip to content

Commit

Permalink
Patch inconsistent hook arguments passed to woocommerce_blocks_valida…
Browse files Browse the repository at this point in the history
…te_location_address_fields by Woo core.
  • Loading branch information
dennisnissle committed Aug 27, 2024
1 parent fda44dc commit b9d3913
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion includes/class-wc-gzd-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ public function set_free_shipping_filter( $cart ) {
}

public function free_shipping_auto_select( $rates ) {
$do_check = is_checkout() || is_cart() || self::$force_free_shipping_filter;
$do_check = is_checkout() || is_cart() || WC_germanized()->is_rest_api_request() || self::$force_free_shipping_filter;

if ( ! $do_check ) {
return $rates;
Expand Down
14 changes: 12 additions & 2 deletions src/Blocks/Checkout.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Vendidero\Germanized\Blocks;

use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields;
use Automattic\WooCommerce\StoreApi\Exceptions\RouteException;
use Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema;
use Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema;
Expand Down Expand Up @@ -242,8 +243,17 @@ function( $errors, $fields, $group ) {
return $errors;
}

$country = isset( $fields['country'] ) ? $fields['country'] : $fields['shipping_country'];
$address_1 = isset( $fields['address_1'] ) ? $fields['address_1'] : $fields['shipping_address_1'];
$country = isset( $fields['country'] ) ? $fields['country'] : $fields[ "{$group}_country" ];
$address_1 = isset( $fields['address_1'] ) ? $fields['address_1'] : $fields[ "{$group}_address_1" ];

/**
* Somehow Woo calls the filter differently on my account address save action
* by handing over the registered fields instead of the actual values.
*/
if ( is_array( $country ) ) {
$country = isset( $_POST[ $group . '_country' ] ) ? wc_clean( wp_unslash( $_POST[ $group . '_country' ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$address_1 = isset( $_POST[ $group . '_address_1' ] ) ? wc_clean( wp_unslash( $_POST[ $group . '_address_1' ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
}

if ( ! empty( $country ) && ! empty( $address_1 ) && apply_filters( 'woocommerce_gzd_checkout_validate_street_number', true, $fields ) ) {
$countries = array();
Expand Down

0 comments on commit b9d3913

Please sign in to comment.