• Resolved alexli126

    (@alexli126)


    Hello,

    I am trying to achieve Google ads enhanced conversion:
    https://support.google.com/google-ads/answer/9888656?hl=en

    It require two fields to submit to Google: Tel No, and email address of customer.

    For the Tel No., it must be international format.

    However, When I use the debug tool of EC assistant at

    https://chromewebstore.google.com/detail/ec-assist/ocbgeehdokdphajhdlbklbccnlknjnai?pli=1

    I note that the telphone No is still not meet the requirement even if this plugin is activated:

    https://prnt.sc/wH9jfrVMLrvo

    The phone number you selected is not suitable for EC because it is incorrectly formatted. Phone numbers should be provided in E.164 format with [+][country code][subscriber number including area code] and can have a maximum of fifteen digits.

    Please validate the implementation using EC Assist again once the formatting is fixed.

    The user-data you selected was captured after the Conversion was already detected. For Enhanced Conversions to work, user-data should be captured prior to the conversion.

    For now, I deactivated this plugin and use the following javascript, it works perfect:

    // Add country calling code prefix in woocommerce billing phone
    // Register WordPress hooks and callbacks for the WooCommerce checkout.
    add_action( 'wp_footer', 'wpsh_add_callback_script' );
    add_action( 'wp_ajax_nopriv_append_country_prefix_in_billing_phone', 'wpsh_add_phone_prefix' );
    add_action( 'wp_ajax_append_country_prefix_in_billing_phone', 'wpsh_add_phone_prefix' );
    add_action( 'woocommerce_checkout_process', 'wpsh_validate_phone' );

    /* Outputs the JavaScript required for updating the billing phone with the country prefix. */
    function wpsh_add_callback_script() {
    // Securely pass data to JavaScript.
    $ajax_url = admin_url('admin-ajax.php');
    ?>
    <script type="text/javascript">
    (function($) {
    $(document.body).on('updated_checkout', function() {
    var country_code = $('#billing_country').val();
    var ajax_data = {
    action: 'append_country_prefix_in_billing_phone',
    country_code: country_code
    };

    $.post('<?php echo esc_js($ajax_url); ?>', ajax_data, function(response) {
    $('#billing_phone').val(response);
    });
    });
    })(jQuery);
    </script>
    <?php
    }

    /* Handles AJAX request to append the country calling code to the billing phone field. */
    function wpsh_add_phone_prefix() {
    $country_code = isset($_POST['country_code']) ? sanitize_text_field($_POST['country_code']) : '';
    $calling_code = '';

    if ($country_code) {
    $calling_codes = WC()->countries->get_country_calling_code($country_code);
    $calling_code = is_array($calling_codes) ? $calling_codes[0] : $calling_codes;
    }

    echo $calling_code;
    wp_die();
    }

    /* Validates the phone number length during the WooCommerce checkout process. */
    function wpsh_validate_phone() {
    if (isset($_POST['billing_phone']) && strlen(preg_replace('/[^0-9]/', '', $_POST['billing_phone'])) < 6) {
    wc_add_notice(__('Billing Phone must be at least 6 digits long.', 'woocommerce'), 'error');
    }
    }

    Could you please have a check and improve the plugin?

    Thanks

    • This topic was modified 3 weeks, 2 days ago by alexli126.
Viewing 1 replies (of 1 total)
  • Plugin Author Mohamed Endisha

    (@endisha)

    @alexli126

    The plugin is working correctly to save the phone number in E.164 format. You can verify the data in the _postmeta table, where it should be stored as [+][country code][phone number].

    We will investigate this in the next release to see if there’s anything we can improve on our end.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.