@@ -402,17 +402,27 @@ function swiftcomplete_settings_menu()
402
402
function add_swiftcomplete_billing ()
403
403
{
404
404
$ 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
+
405
410
wp_enqueue_script ('swiftcomplete_script ' , 'https://script.swiftcomplete.com/js/swiftcomplete.js ' );
406
411
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 ' ]) : '' ) . '") ' ));
408
413
}
409
414
410
415
function add_swiftcomplete_shipping ()
411
416
{
412
417
$ 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
+
413
423
wp_enqueue_script ('swiftcomplete_script ' , 'https://script.swiftcomplete.com/js/swiftcomplete.js ' );
414
424
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 ' ]) : '' ) . '") ' ));
416
426
}
417
427
418
428
add_action ('woocommerce_checkout_billing ' , 'add_swiftcomplete_billing ' );
0 commit comments