• Resolved dd2006

    (@dd2006)


    hi I found this file:

    wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-data.php

    I think he generates the page where I see the orders and I would like to make sure that the link where the phone number of the person ordering is placed instead of having me call the person sends me to a WhatsApp chat or maybe have both above the number with the call link and below the number with the chat link

    this code at line 479

                      <div class="address">
                            <?php
    
                            // Display values.
                            if ( $order->get_formatted_shipping_address() ) {
                                echo '<p>' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '</p>';
                            } else {
                                echo '<p class="none_set"><strong>' . esc_html__( 'Address:', 'woocommerce' ) . '</strong> ' . esc_html__( 'No shipping address set.', 'woocommerce' ) . '</p>';
                            }
    
                            if ( ! empty( self::$shipping_fields ) ) {
                                foreach ( self::$shipping_fields as $key => $field ) {
                                    if ( isset( $field['show'] ) && false === $field['show'] ) {
                                        continue;
                                    }
    
                                    $field_name = 'shipping_' . $key;
    
                                    if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
                                        $field_value = $order->{"get_$field_name"}( 'edit' );
                                    } else {
                                        $field_value = $order->get_meta( '_' . $field_name );
                                    }
    
                                    if ( 'shipping_phone' === $field_name ) {
                                        $field_value = wc_make_phone_clickable( $field_value );
                                    }
    
                                    if ( $field_value ) {
                                        echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
                                    }
                                }
                            }
    
                            if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $order->get_customer_note() ) { // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
                                echo '<p class="order_note"><strong>' . esc_html( __( 'Customer provided note:', 'woocommerce' ) ) . '</strong> ' . nl2br( esc_html( $order->get_customer_note() ) ) . '</p>';
                            }
                            ?>
                        </div>

    what I would like to do is add a code that duplicates the number, one with the “tel:” protocol and just below with the WhatsApp API protocol, but I can’t because I don’t know how to recover the clean number. I would like something like this to add this code:

     <?php 
    $phonewa = " "; // how i can insert the number??
    
    // clean number
    $phonewa = preg_replace('/[^0-9]/', '', $phone);
    
    // verify no empity
    if (!empty($phonewa)) {
        // link WhatsApp
        $whatsappLink = "https://api.whatsapp.com/send?phone=+$phonewa";
        
        // print link
        echo "<a href='$whatsappLink'>send on WhatsApp</a>";
    } else {
        echo "invalid";
    }
    ?

    but I don’t know what to write in here to get the number:

    $phonewa = ” HERE “; // how i can insert the get number??

    Thank you for your help and support

    • This topic was modified 2 years, 6 months ago by dd2006.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Shameem – a11n

    (@shameemreza)

    Hi @dd2006

    I understand that you are trying to customize your WooCommerce store to include a WhatsApp chat link for each customer’s phone number.

    However, editing core WooCommerce files is not recommended as it can lead to issues when updating the plugin in the future. Instead, consider creating a custom plugin or using a child theme to override the specific function.

    Regarding your question about retrieving the phone number, you can use the same method that WooCommerce uses to get the shipping phone number.

    Additionally, you can use a plugin to achieve it, like Digits, Order on WhatsApp for WooCommerce, or Social Notifications for WooCommerce plugin.

    If still you need assistance with customization or development with your site, we recommend that you seek help from:

    If you are comfortable with coding yourself and have questions, I would also recommend that you consider:

    I hope that helps you to figure it out.

    Thread Starter dd2006

    (@dd2006)

    Hello and thanks! but I would simply like to modify the page and insert it into a child or override in order to be able to make updates. Tell me what to write in here:

    $phonewa = ” HERE “; // how i can insert the get number??

    Hi there @dd2006 👋

    Let’s loop back to the original inquiry for a moment:

    I would like to make sure that the link where the phone number of the person ordering is placed instead of having me call the person sends me to a WhatsApp chat or maybe have both above the number with the call link and below the number with the chat link

    This can be achieved by inserting a hyperlink, like the following:

    <a target=“_blank” href="https://wa.me/34123456789/?text=WhatsApp%20with%20us">Chat/call with us via WhatsApp</a>

    In the above example:

    • Replace 34123456789 with your number
    • Any text string can replace WhatsApp%20with%20us, provided %20 is used, instead of spaces

    Finally, include the file with this edit in your child theme’s directory, for making it upgrade-safe.

    I trust that points you in the right direction, but if you have more questions, let us know.

    We’re happy to help.

    Thread Starter dd2006

    (@dd2006)

    Thank you!

    but I would like to make sure that the link can be clicked by me and that a chat opens with the customer and not the other way around and therefore what you suggested for which I thank you.

    See this screenshot of the woocommerce order page to understand better.

    https://snipboard.io/yqQUCa.jpg

    thanks for any advice

    Saif

    (@babylon1999)

    Hello @dd2006,

    Thank you for the clarification!

    Try this:

    add_action('woocommerce_order_item_add_action_buttons', 'add_custom_button_to_order');
    
    function add_custom_button_to_order($order) {
    
        $billing_phone = $order->get_billing_phone();
        if (!empty($billing_phone)) {
            $redirect_url = 'https://wa.me/' . urlencode($billing_phone);
            echo '<a target="_blank" class="button" href="' . esc_url($redirect_url) . '"> Message Customer on WhatsApp</a>';
        }
    }
    

    I placed it next to the refund button, if you’d prefer to add it somewhere else, you can check the available hooks in the order templates here: https://github.com/woocommerce/woocommerce/tree/60b4502e408072a662f0d898690cef9e977dfff4/plugins/woocommerce/includes/admin/meta-boxes/views

    Please note that custom solutions are not something we can assist with per our support policy, as mentioned above. If you’d to customize this further, consider hiring a WooExpert.

    Hope this helps!

    Thread Starter dd2006

    (@dd2006)

    Thank you so much, this little script works regularly.

    Saif

    (@babylon1999)

    Thank you so much, this little script works regularly.

    I’m glad it did! :‎)

    I will mark the thread as solved. If you have a few minutes, we’d love it if you could leave us a review: https://wordpress.org/support/plugin/woocommerce/reviews/

    Cheers!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘woocommerce put wa.me link instead of tel’ is closed to new replies.