Hide a custom action button on click displaying a text in WooCommerce admin orders list Hide a custom action button on click displaying a text in WooCommerce admin orders list wordpress wordpress

Hide a custom action button on click displaying a text in WooCommerce admin orders list


Javascript is not the way to achieve this. You will use the following instead to hide the link and display "Message sent" once an external link has been clicked:

add_filter( 'manage_edit-shop_order_columns', 'dvs_whatsapp_msg_list_column' );function dvs_whatsapp_msg_list_column( $columns ) {    $columns['whatsapp'] = __('WhatsApp', 'woocommerce');    return $columns;}add_action( 'manage_shop_order_posts_custom_column', 'dvs_whatsapp_msg_list_column_content' );function dvs_whatsapp_msg_list_column_content( $column ) {    if ( 'whatsapp' === $column ) {        global $the_order;        if( ! $the_order->get_meta('_wapp_sent') ) {            echo '<a href="?post_type=shop_order&send=dvs_whatsapp&order_id=' . $the_order->get_id() .' target="blank" class="dvs-whatsapp button">' . __("Send WhatsApp") . '</a>';        }        else {            echo __("Message sent", "woocommerce");        }    }}add_action( 'admin_init', 'dvs_redirect_whatsapp_send' );function dvs_redirect_whatsapp_send() {    global $pagenow;    # Check current admin page.    if ( $pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'shop_order'    && isset($_GET['send']) && $_GET['send'] == 'dvs_whatsapp' && isset($_GET['order_id']) && $_GET['order_id'] > 0 ) {        $order = wc_get_order( $_GET['order_id'] );        $msg = sprintf( __("Hello %s %s, your order #%s has been received. The order amount is %s. Your payment method is %s. %s", "woocommerce"),            $order->get_billing_first_name(),            $order->get_billing_last_name(),            $order->get_order_number(),            $order->get_total(),            $order->get_payment_method_title(),            __("Please contact us if you have any question regarding your order. Thank you.", "woocommerce")        );        $whatsapp_num = WC()->countries->get_country_calling_code( $order->get_billing_country() ) . $order->get_billing_phone();        update_post_meta( $_GET['order_id'], '_wapp_sent', 'true' ); // Mark order as WhatsApp message sent        wp_redirect( 'https://wa.me/' . $whatsappnum . '?text=' . urlencode($msg) ); // Redirect to WhatsApp sending service        exit;    }}

Code goes in functions.php file of your active child theme (or active theme). Tested and works.


I believe this should do the trick:

jQuery to insert on your page

jQuery('.dvs-whatsapp-btn').click(function(){    jQuery('<span class="link-clicked">Link clicked!</span>').insertAfter('.dvs-whatsapp-btn');    jQuery('.dvs-whatsapp-btn').hide();});