Skip to content

Commit a04ddb5

Browse files
authored
Fix terminal location creation if site title is missing (#2361)
* Fix terminal location creation if site title is missing * Strip protocol from store hostname
1 parent 7611944 commit a04ddb5

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 6.5.0 - 2022-xx-xx =
4+
* Fix - Fix terminal location creation if site title is missing.
45

56
= 6.4.1 - 2022-06-01 =
67
* Fix - Ensure proper URL formatting.

includes/admin/class-wc-rest-stripe-locations-controller.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ public function get_location( $request ) {
178178
* @param WP_REST_Request $request Full data about the request.
179179
*/
180180
public function get_store_location( $request ) {
181-
$name = get_bloginfo();
181+
// Originally `get_bloginfo` was used for location name, later switched to `site_url` as the former may be blank.
182+
$store_hostname = str_replace( [ 'https://', 'http://' ], '', get_site_url() );
183+
$possible_names = [ get_bloginfo(), $store_hostname ];
182184
$store_address = WC()->countries;
183185
$address = array_filter(
184186
[
@@ -213,7 +215,7 @@ public function get_store_location( $request ) {
213215
try {
214216
foreach ( $this->fetch_locations() as $location ) {
215217
if (
216-
$location->display_name === $name
218+
in_array( $location->display_name, $possible_names, true )
217219
&& count( array_intersect( (array) $location->address, $address ) ) === count( $address )
218220
) {
219221
return rest_ensure_response( $location );
@@ -223,7 +225,7 @@ public function get_store_location( $request ) {
223225
// Create new location if no location matches display name and address.
224226
$response = WC_Stripe_API::request(
225227
[
226-
'display_name' => $name,
228+
'display_name' => $store_hostname,
227229
'address' => $address,
228230
],
229231
'terminal/locations'

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,6 @@ If you get stuck, you can ask for help in the Plugin Forum.
129129
== Changelog ==
130130

131131
= 6.5.0 - 2022-xx-xx =
132+
* Fix - Fix terminal location creation if site title is missing.
132133

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

0 commit comments

Comments
 (0)