-
Notifications
You must be signed in to change notification settings - Fork 219
Hide "collection from" text when a location has an incomplete address. #9808
Conversation
The release ZIP for this PR is accessible via:
Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
Size Change: +1.33 kB (0%) Total Size: 1.17 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't working for me. Am I missing anything?
Screen.Recording.2023-06-16.at.11.39.52.AM.mov
@tarunvijwani thats the trunk behaviour. I just retested and its fine in this branch. Suggest rebuilding and clearing caches, or someone else from @woocommerce/rubik can try it. |
@mikejolley I'm getting the same result as @tarunvijwani. To ensure that I'm starting with a fresh environment, I ran the following commands: rm composer.lock
rm package-lock.json
rm -rf node_modules
rm -rf vendor
nvm use
composer i
npm i
npm run build
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You were right! I was testing it on WooCommerce 7.9. Forgot to enable the WC Blocks plugin after the release.😃
It works as expected. Great work! 🎉
I left one suggestion for the countries where state is an optional field. Let me know your thoughts about it.
src/Shipping/PickupLocation.php
Outdated
@@ -42,6 +56,7 @@ public function calculate_shipping( $package = array() ) { | |||
if ( ! $location['enabled'] ) { | |||
continue; | |||
} | |||
$has_pickup_address = ! empty( $location['address'] ) && ! empty( $location['address']['city'] ) && ! empty( $location['address']['state'] ) && ! empty( $location['address']['country'] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some countries like UAE don't have a state. This condition will hide the Collection from
for them as well.
I feel we should have helper function that will check the address completeness based on the country.
We have one similar function: isAddressComplete
in utils. Do you think we should utilize it here?
You can test that with the below address:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code wise it looks great, Tarun's suggestion is valid though! We should avoid checking for fields that may are not required for that locale.
What do you think of this?
$required_address_fields_for_country = [];
if ( ! empty( $location['address']['country'] ) ) {
$shipping_address_fields = wc()->countries->get_address_fields( $location['address']['country'], 'shipping_' );
foreach ( $shipping_address_fields as $field_name => $field ) {
if ( true === $field['required'] ) {
$required_address_fields_for_country[] = str_replace( 'shipping_', '', $field_name );
}
}
}
$has_pickup_address = ! empty( $location['address'] ) &&
( ! empty( $location['address']['city'] ) || ! in_array( 'city', $required_address_fields_for_country, true ) ) &&
( ! empty( $location['address']['state'] ) || ! in_array( 'state', $required_address_fields_for_country, true ) ) &&
( ! empty( $location['address']['country'] ) );
I added a helper in b4bfc94 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That helper function is a much cleaner way of doing it than I suggested, nice one!
Do you think we should add tests for it? We could add an issue for this and write them later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarunvijwani missed a check to see if the field was included in address_fields. Try now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great! Thank you for the changes! 🎉
Hides the "collection from
" section when a local pickup location has no defined address. This prevents repetition of the local pickup rate name, or nonsensical text.Fixes #9789
User Facing Testing
WooCommerce Visibility
Changelog