Adding OneClick Chat to Order and WhatsApp Checkout in WordPress With Shipping Method

To add a One-Click Chat to Order feature and send checkout details via WhatsApp, including the shipping method, you can make modifications to the “wa_button.php” file in your WordPress theme or plugin. Here’s a step-by-step guide on how to achieve this:

  1. Open the “wa_button.php” file and locate the function where the WhatsApp message is being constructed. It might look something like this:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
function create_whatsapp_message($order) {
    // Existing code for creating the WhatsApp message
    $message = "Hello, thank you for your order!\r\n";
    // ...
    // More existing code
    // ...
    $date = $order->get_date_created()->format ('F j, Y - g:i A');
    // Add the shipping method information
    $shipping_method = "*Metode Pengiriman:*\r\n".$order->get_shipping_method()." ".$order->get_shipping_total()."\r\n";
    
    // Final output of the message
    $message .= "\r\n".$total_price."\r\n".$shipping_method."\r\n".$payment."\r\n*".$customer."* ".$address."\r\n\r\n".$thanks_label."\r\n\r\n(".$date.")";
    // Return the message
    return $message;
}
  1. Modify the existing code as shown above to include the shipping method information.

  2. Save the changes to the “wa_button.php” file.

  3. Once you have made the changes, you need to create a function that will trigger the WhatsApp message when the “One-Click Chat to Order” button is clicked. This function should call the “create_whatsapp_message” function and then send the message using WhatsApp.

  4. Implement this new function in your WordPress template or plugin where the “One-Click Chat to Order” button is located.

Please note that the above code assumes that you have already retrieved all the necessary variables like $total_price, $payment, $customer, $address, and $thanks_label.

Finally, make sure to test the functionality thoroughly to ensure that the WhatsApp message is sent with the correct order details, including the shipping method.

0%