Created
March 15, 2019 14:15
-
-
Save LiamBailey/9af393abb1e50be9393793f1063fb929 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function get_location_select_html( $object_id, $chosen_location = null, $product = null ) { | |
$object_type = $this->get_object_type(); | |
$enhanced_search = $this->use_enhanced_search(); | |
$field_name = wc_local_pickup_plus_shipping_method()->is_per_item_selection_enabled() ? '_pickup_location_id' : '_shipping_method_pickup_location_id'; | |
if ( $using_single_location = $this->get_product_pickup_location( $product ) ) { | |
$chosen_location = $using_single_location; | |
$using_single_location = true; | |
} elseif ( ! $chosen_location ) { | |
$using_single_location = false; | |
$chosen_location = $this->get_user_default_pickup_location(); | |
} else { | |
$using_single_location = false; | |
} | |
ob_start(); ?> | |
<?php if ( ! $using_single_location ) : ?> | |
<div | |
id="pickup-location-lookup-area-field-for-<?php echo esc_attr( $object_id ); ?>" | |
class="pickup-location-lookup-area-field" | |
data-pickup-object-id="<?php echo esc_attr( $object_id ); ?>" | |
<?php if ( ! $enhanced_search ) { echo 'style="display: none;"'; } ?>> | |
<small | |
class="pickup-location-current-lookup-area" | |
<?php if ( ! $enhanced_search ) { echo 'style="display: none;"'; } ?>><?php | |
$change = '<a class="pickup-location-change-lookup-area" href="#">' . strtolower( esc_html__( 'Change', 'woocommerce-shipping-local-pickup-plus' ) ) . '</a>'; | |
/* translators: Placeholder: %s - country or state name (or "Anywhere") */ | |
printf( __( 'Enter a postcode or city to search for pickup locations from: %s', 'woocommerce-shipping-local-pickup-plus' ) . ' (' . $change . ')', '<em class="pickup-location-current-lookup-area-label">' . $this->get_lookup_area_label() . '</em>' ); ?> | |
</small> | |
<div style="display: none;"> | |
<?php echo $this->get_country_state_dropdown( $object_id ); ?> | |
</div> | |
</div> | |
<?php endif; ?> | |
<?php if ( ! $enhanced_search || $using_single_location ) : ?> | |
<?php $pickup_locations = ! $using_single_location ? $this->get_all_pickup_locations() : array( $chosen_location->get_id() => $chosen_location ); ?> | |
<?php $chosen_location = array_key_exists( $chosen_location ? $chosen_location->get_id() : null, $pickup_locations ) ? $chosen_location : null ?> | |
<select | |
name="<?php echo sanitize_html_class( $field_name ); ?>[<?php echo esc_attr( $object_id ); ?>]" | |
class="pickup-location-lookup" | |
style="width: 100%; max-width: 512px; <?php echo $using_single_location ? ' display: none;' : ''; ?>" | |
data-placeholder="<?php esc_attr_e( 'Search locations…', 'woocommerce-shipping-local-pickup-plus' ); ?>" | |
<?php if ( $using_single_location ) : ?> | |
data-single-pickup-location="<?php echo esc_attr( $chosen_location->get_id() ); ?>" | |
<?php endif; ?> | |
data-pickup-object-type="<?php echo esc_attr( $object_type ); ?>" | |
data-pickup-object-id="<?php echo esc_attr( $object_id ); ?>" > | |
<option></option> | |
<?php foreach ( $pickup_locations as $pickup_location ) : ?> | |
<?php if ( $this->can_be_picked_up( $pickup_location ) ) : ?> | |
<?php $address = $pickup_location->get_address(); ?> | |
<option | |
data-postcode="<?php echo esc_attr( $address->get_postcode() ); ?>" | |
data-city="<?php echo esc_attr( $address->get_city() ); ?>" | |
data-address="<?php echo esc_attr( str_replace( array( '-', ',', '.', '#', '°' ), '', $address->get_street_address( 'string', ' ' ) ) ); ?>" | |
value="<?php echo esc_attr( $pickup_location->get_id() ); ?>" | |
<?php selected( $pickup_location->get_id(), ( $chosen_location ? $chosen_location->get_id() : null ), true ); ?>> | |
<?php echo esc_html( $pickup_location->get_name() ); ?> | |
</option> | |
<?php endif; ?> | |
<?php endforeach; ?> | |
</select> | |
<?php if ( $using_single_location ) : ?> | |
<?php if ( wc_local_pickup_plus_shipping_method()->is_per_order_selection_enabled() ) : ?> | |
<?php if ( is_checkout() ) : ?> | |
<?php echo $chosen_location->get_name(); ?> | |
<?php else : ?> | |
<small><?php | |
/* translators: Placeholder: %s - pickup location name */ | |
printf( esc_html__( 'Pickup Location: %s', 'woocommerce-shipping-local-pickup-plus' ), $chosen_location->get_name() ); ?></small> | |
<?php endif; ?> | |
<?php else : // == wc_local_pickup_plus_shipping_method()->is_per_item_selection_enabled() ?> | |
<small><abbr | |
title="<?php echo esc_attr( $chosen_location->get_address()->get_formatted_html( true ) ); ?>"><?php | |
/* translators: Placeholder: %s - pickup location name */ | |
printf( esc_html__( 'Pickup Location: %s', 'woocommerce-shipping-local-pickup-plus' ), $chosen_location->get_name() ); ?></abbr></small> | |
<?php endif ?> | |
<?php endif ?> | |
<?php else : ?> | |
<?php if ( SV_WC_Plugin_Compatibility::is_wc_version_gte_3_0() ) : ?> | |
<select | |
name="<?php echo sanitize_html_class( $field_name ); ?>[<?php echo esc_attr( $object_id ); ?>]" | |
class="pickup-location-lookup" | |
style="width:100%; max-width:512px;" | |
data-placeholder="<?php esc_attr_e( 'Search locations…', 'woocommerce-shipping-local-pickup-plus' ); ?>" | |
data-pickup-object-type="<?php echo esc_attr( $object_type ); ?>" | |
data-pickup-object-id="<?php echo esc_attr( $object_id ); ?>"> | |
<option></option> | |
<?php if ( $chosen_location instanceof WC_Local_Pickup_Plus_Pickup_Location ) : ?> | |
<option value="<?php echo $chosen_location->get_id(); ?>" selected="selected"><?php echo esc_html( $chosen_location->get_name() ); ?></option> | |
<?php endif; ?> | |
</select> | |
<?php else : ?> | |
<input | |
type="hidden" | |
name="<?php echo sanitize_html_class( $field_name ); ?>[<?php echo esc_attr( $object_id ); ?>]" | |
class="pickup-location-lookup" | |
style="width:100%; max-width:512px;" | |
value="<?php echo $chosen_location ? $chosen_location->get_id() : ''; ?>" | |
data-placeholder="<?php esc_attr_e( 'Search locations…', 'woocommerce-shipping-local-pickup-plus' ); ?>" | |
data-pickup-object-type="<?php echo esc_attr( $object_type ); ?>" | |
data-pickup-object-id="<?php echo esc_attr( $object_id ); ?>" | |
/> | |
<span | |
class="pickup-location-lookup-data" | |
data-pickup-object-type="<?php echo esc_attr( $object_type ); ?>" | |
data-pickup-object-id="<?php echo esc_attr( $object_id ); ?>" | |
></span> | |
<?php endif; ?> | |
<?php endif; ?> | |
<?php return ob_get_clean(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment