Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Last active June 4, 2025 11:30
Show Gist options
  • Save xlplugins/1df258fb8030a4c10cda4cc2e7f0bd5a to your computer and use it in GitHub Desktop.
Save xlplugins/1df258fb8030a4c10cda4cc2e7f0bd5a to your computer and use it in GitHub Desktop.
Fetchify Address Autocomplete
class WFACP_Fetchify{
public function __construct() {
add_action('wfacp_before_form',[$this, 'add_fields']);
add_filter( 'wfacp_internal_css', [ $this, 'add_css_js' ] );
}
public function add_fields() {
$instance=WFACP_Common::remove_actions('woocommerce_checkout_billing','WC_ClickToAddress_Autocomplete_Integration','addCheckoutJs');
if($instance instanceof WC_ClickToAddress_Autocomplete_Integration){
add_action('woocommerce_before_checkout_form',[$instance,'addCheckoutJs']);
}
}
public function add_css_js() {
?>
<style>
.wfacp_shipping_fields.wfacp_shipping_field_hide,
p#crafty_shipping_button > label,
p#crafty_billing_button > label,
p.cc_c2a_hide{
display: none !important;
}
p#shipping_postcode_search_field input#shipping_postcode_search,
p#billing_postcode_search_field input#billing_postcode_search
{
padding: 12px !important;
}
</style>
<script>
(function($){
jQuery(document).ready(function($) {
function checkPostcodeLength() {
if($('#shipping_postcode_search_field').length > 0){
$('#shipping_postcode_search_field').addClass(' wfacp-form-control-wrapper wfacp-col-full');
$('#shipping_postcode_search_field').parent('p').find('wfacp-form-control-label');
$('#crafty_shipping_button').addClass('wfacp-form-control-wrapper wfacp-col-full');
if($('#shipping_same_as_billing').length > 0 ){
$('#shipping_postcode_search_field').addClass('wfacp_shipping_fields wfacp_shipping_field_hide');
$('#crafty_shipping_button').addClass('wfacp_shipping_fields wfacp_shipping_field_hide');
}
}
if($('#billing_postcode_search_field').length > 0){
$('#billing_postcode_search_field').addClass('wfacp-form-control-wrapper wfacp-col-full');
$('#billing_postcode_search_field').parent('p').find('wfacp-form-control-label');
$('#crafty_billing_button').addClass('wfacp-form-control-wrapper wfacp-col-full');
if($('#billing_same_as_shipping').length > 0 ){
$('#billing_postcode_search_field').addClass('wfacp_billing_fields wfacp_billing_field_hide');
$('#crafty_billing_button').addClass('wfacp_billing_fields wfacp_billing_field_hide');
}
}
if($('.cc_c2a_search_input').length > 0){
$('.cc_c2a_search_input').parent('p').addClass(' wfacp-form-control-wrapper wfacp-col-full');
$('.cc_c2a_search_input').parent('p').find('label').addClass(' wfacp-form-control-label');
$('.cc_c2a_search_input').addClass('wfacp-form-control');
if($('#billing_same_as_shipping').length > 0 ){
$('#billing_cc_c2a_search_input').parent('p').addClass(' wfacp_billing_fields wfacp_billing_field_hide');
}
if($('#shipping_same_as_billing').length > 0 ){
$('#shipping_cc_c2a_search_input').parent('p').addClass('wfacp_shipping_fields wfacp_shipping_field_hide');
}
}
}
setTimeout(function(){
checkPostcodeLength();
},1500);
});
})(jQuery);
</script>
<?php
}
}
new WFACP_Fetchify();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment