Skip to content

Commit ae41eec

Browse files
committed
Implement delivery restrictions (simple and basic)
1 parent 3e41c7f commit ae41eec

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

includes/class-wc-amazon-payments-advanced-api.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ protected static function create_checkout_session_params( $redirect_url = null )
142142
),
143143
);
144144

145+
$countries = WC()->countries->get_shipping_countries();
146+
$all_countries = WC()->countries->get_countries();
147+
if ( count( $countries ) !== count( $all_countries ) ) {
148+
$restrictions = array();
149+
foreach ( $countries as $country => $name ) {
150+
$restrictions[ $country ] = new stdClass(); // If we use an empty array it'll be treated as an array in JSON
151+
}
152+
$payload['deliverySpecifications'] = array(
153+
'addressRestrictions' => array(
154+
'type' => 'Allowed',
155+
'restrictions' => $restrictions,
156+
),
157+
);
158+
}
159+
145160
$payload = wp_json_encode( $payload, JSON_UNESCAPED_SLASHES );
146161

147162
return $payload;

0 commit comments

Comments
 (0)