Skip to content

Commit cf4350a

Browse files
author
=
committed
Added check for API key
1 parent 3d80846 commit cf4350a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

swiftcomplete.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,17 +402,27 @@ function swiftcomplete_settings_menu()
402402
function add_swiftcomplete_billing()
403403
{
404404
$settings = get_option('swiftcomplete_settings');
405+
$api_key = '';
406+
407+
if (array_key_exists('api_key', $settings) && strlen($settings['api_key']) > 0)
408+
$api_key = $settings['api_key'];
409+
405410
wp_enqueue_script('swiftcomplete_script', 'https://script.swiftcomplete.com/js/swiftcomplete.js');
406411
wp_enqueue_script('swiftcomplete_launch', plugin_dir_url(__FILE__) . 'addressfinder.js', array('jquery'));
407-
wp_add_inline_script('swiftcomplete_launch', sprintf('launchAddressLookup("billing", "' . esc_attr($settings['api_key']) . '", "' . (array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'address,what3words' : 'address') . '", "' . (array_key_exists('hide_fields', $settings) && $settings['hide_fields'] ? true : false) . '", "' . (array_key_exists('bias_towards_lat_lon', $settings) ? esc_attr($settings['bias_towards_lat_lon']) : '') . '", "' . (array_key_exists('billing_placeholder', $settings) ? esc_attr($settings['billing_placeholder']) : '') . '")'));
412+
wp_add_inline_script('swiftcomplete_launch', sprintf('launchAddressLookup("billing", "' . esc_attr($api_key) . '", "' . (array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'address,what3words' : 'address') . '", "' . (array_key_exists('hide_fields', $settings) && $settings['hide_fields'] ? true : false) . '", "' . (array_key_exists('bias_towards_lat_lon', $settings) ? esc_attr($settings['bias_towards_lat_lon']) : '') . '", "' . (array_key_exists('billing_placeholder', $settings) ? esc_attr($settings['billing_placeholder']) : '') . '")'));
408413
}
409414

410415
function add_swiftcomplete_shipping()
411416
{
412417
$settings = get_option('swiftcomplete_settings');
418+
$api_key = '';
419+
420+
if (array_key_exists('api_key', $settings) && strlen($settings['api_key']) > 0)
421+
$api_key = $settings['api_key'];
422+
413423
wp_enqueue_script('swiftcomplete_script', 'https://script.swiftcomplete.com/js/swiftcomplete.js');
414424
wp_enqueue_script('swiftcomplete_launch', plugin_dir_url(__FILE__) . 'addressfinder.js', array('jquery'));
415-
wp_add_inline_script('swiftcomplete_launch', sprintf('launchAddressLookup("shipping", "' . esc_attr($settings['api_key']) . '", "' . (array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'address,what3words' : 'address') . '", "' . (array_key_exists('hide_fields', $settings) && $settings['hide_fields'] ? true : false) . '", "' . (array_key_exists('bias_towards_lat_lon', $settings) ? esc_attr($settings['bias_towards_lat_lon']) : '') . '", "' . (array_key_exists('shipping_placeholder', $settings) ? esc_attr($settings['shipping_placeholder']) : '') . '")'));
425+
wp_add_inline_script('swiftcomplete_launch', sprintf('launchAddressLookup("shipping", "' . esc_attr($api_key) . '", "' . (array_key_exists('w3w_enabled', $settings) && $settings['w3w_enabled'] ? 'address,what3words' : 'address') . '", "' . (array_key_exists('hide_fields', $settings) && $settings['hide_fields'] ? true : false) . '", "' . (array_key_exists('bias_towards_lat_lon', $settings) ? esc_attr($settings['bias_towards_lat_lon']) : '') . '", "' . (array_key_exists('shipping_placeholder', $settings) ? esc_attr($settings['shipping_placeholder']) : '') . '")'));
416426
}
417427

418428
add_action('woocommerce_checkout_billing', 'add_swiftcomplete_billing');

0 commit comments

Comments
 (0)