Skip to content

Commit

Permalink
Pickup delivery order notes missing fallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Jun 11, 2024
1 parent 292d22f commit b642bcd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
27 changes: 18 additions & 9 deletions assets/js/static/pickup-locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ window.germanized.shipments_pickup_locations = window.germanized.shipments_picku

var $pickupSelect = self.getPickupLocationSelect();

if ( $pickupSelect.length > 0 ) {
self.pickupLocations = $pickupSelect.data( 'locations' );
if ( $pickupSelect.length > 0 && $pickupSelect.attr( 'data-locations' ) ) {
try {
self.pickupLocations = JSON.parse( $pickupSelect.attr( 'data-locations' ) );
} catch (e) {
self.pickupLocations = {};
}
}

if ( $( '#current_pickup_location' ).length > 0 ) {
Expand Down Expand Up @@ -103,7 +107,7 @@ window.germanized.shipments_pickup_locations = window.germanized.shipments_picku
$notice = $( '.pickup_location_notice' );

if ( currentCode && currentPickupLocation ) {
$current.attr( 'data-current-location', currentPickupLocation );
$current.attr( 'data-current-location', JSON.stringify( currentPickupLocation ) );

self.replaceShippingAddress( currentPickupLocation.address_replacements );
self.updateCustomerNumberField( currentPickupLocation );
Expand Down Expand Up @@ -174,7 +178,10 @@ window.germanized.shipments_pickup_locations = window.germanized.shipments_picku
$pickupSelect = self.getPickupLocationSelect(),
current = $pickupSelect.val();

$pickupSelect.attr('data-locations', self.pickupLocations );
try {
$pickupSelect.attr('data-locations', JSON.stringify( self.pickupLocations ) );
} catch (e) {}

$pickupSelect.find( 'option:not([value=""])' ).remove();

$.each( self.pickupLocations, function( code, pickupLocation ) {
Expand Down Expand Up @@ -283,12 +290,14 @@ window.germanized.shipments_pickup_locations = window.germanized.shipments_picku
} else {
var $select = $( '#current_pickup_location' );

if ( $select.data( 'current-location' ) ) {
var currentLocation = $select.data( 'current-location' );
if ( $select.attr( 'data-current-location' ) ) {
try {
var currentLocation = JSON.parse( $select.attr( 'data-current-location' ) );

if ( currentLocation.code === locationCode ) {
return currentLocation;
}
if ( currentLocation.code === locationCode ) {
return currentLocation;
}
} catch (e) {}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/PickupDelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,14 @@ public static function register_classic_checkout_fields( $fields ) {
'priority' => 62,
);

$fields['order']['current_pickup_location'] = array(
$enable_order_notes_field = apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) );
$current_pickup_location_field_group = 'order';

if ( apply_filters( 'woocommerce_gzd_shipments_render_current_pickup_location_in_billing', ! $enable_order_notes_field ) ) {
$current_pickup_location_field_group = 'billing';
}

$fields[ $current_pickup_location_field_group ]['current_pickup_location'] = array(
'type' => 'wc_gzd_shipments_current_pickup_location',
'current_location' => $pickup_delivery_data['current_location'],
'default' => $pickup_delivery_data['current_location_code'],
Expand Down

0 comments on commit b642bcd

Please sign in to comment.