Fix ERROR creating Xero invoice openPOS Woocommerce

For this case I have openPOS on my wp to order some product but one some case I have problem with xero invoice, because xero invoice canot create invoice if order from openPOS.

“ERROR creating Xero invoice: ErrorNumber: 10 ErrorType: ValidationException Message: A validation exception occurred Detail: The Contact must contain at least 1 of the following elements to identify the contact: Name, ContactID, ContactNumber”

If you pay attention, every order made by OpenPOS is always identified as a guest, so I have idea to set default user if user identified by guest. 

I have two method, if edit by admin or when an order comes in as a guest. Just add litle custom on your functions.php

// Function to change guest orders to a specific user at checkout
function set_default_user_for_guest_orders($order_id, $data) {
    $order = wc_get_order($order_id);
    if ($order->get_customer_id() == 0) {
        $default_user = get_user_by('login', 'root93'); // change 'root93' with username you want
        if ($default_user) {
            $order->set_customer_id($default_user->ID);
            $order->save(); // Simpan perubahan pada order
        }
    }
}
add_action('woocommerce_checkout_update_order_meta', 'set_default_user_for_guest_orders', 20, 2);



// Function to change guest orders to a specific user when saved from the admin page
function set_default_user_for_guest_orders_admin($post_id, $post) {
    if ($post->post_type == 'shop_order') {
        $order = wc_get_order($post_id);
        if ($order && $order->get_customer_id() == 0) {
            $default_user = get_user_by('login', 'root93'); 
            if ($default_user) {
                $order->set_customer_id($default_user->ID);
                $order->save();
            }
        }
    }
}
add_action('save_post', 'set_default_user_for_guest_orders_admin', 20, 2);

See also : Create Default User Xero Invoice for Guest OpenPOS WooCommerce

0 Response to "Fix ERROR creating Xero invoice openPOS Woocommerce "

Post a Comment

Komentar yang Anda kirim akan terlebih dahulu di moderasi oleh Admin