import WooCommerceRestApi from '@woocommerce/woocommerce-rest-api';
type WooCommerce = {
url: string;
consumerKey: string;
consumerSecret: string;
version?: string;
queryStringAuth?: boolean;
};
export async function main(
resource: WooCommerce,
order: {
payment_method: string;
payment_method_title: string;
set_paid: boolean;
billing: {
first_name: string;
last_name: string;
address_1: string;
address_2: string;
city: string;
state: string;
postcode: string;
country: string;
email: string;
phone: string;
};
shipping: {
first_name: string;
last_name: string;
address_1: string;
address_2: string;
city: string;
state: string;
postcode: string;
country: string;
};
line_items: {
product_id: number;
variation_id?: number;
quantity: number;
}[];
shipping_lines: {
method_id: string;
method_title: string;
total: string;
}[];
}
) {
const WooCommerce = new WooCommerceRestApi(resource);
try {
const response = await WooCommerce.post('orders', order);
return response.data;
} catch (error) {
return {
error: true,
message: error.response.data || 'Internal Server Error',
};
}
}
Submitted by hugo697 5 days ago
import WooCommerceRestApi from '@woocommerce/woocommerce-rest-api';
type WooCommerce = {
url: string;
consumerKey: string;
consumerSecret: string;
version?: string;
queryStringAuth?: boolean;
};
export async function main(
resource: WooCommerce,
order: {
payment_method: string;
payment_method_title: string;
set_paid: boolean;
billing: {
first_name: string;
last_name: string;
address_1: string;
address_2: string;
city: string;
state: string;
postcode: string;
country: string;
email: string;
phone: string;
};
shipping: {
first_name: string;
last_name: string;
address_1: string;
address_2: string;
city: string;
state: string;
postcode: string;
country: string;
};
line_items: {
product_id: number;
variation_id?: number;
quantity: number;
}[];
shipping_lines: {
method_id: string;
method_title: string;
total: string;
}[];
}
) {
const WooCommerce = new WooCommerceRestApi(resource);
try {
const response = await WooCommerce.post('orders', order);
return response.data;
} catch (error) {
return {
error: true,
message: error.response.data || 'Internal Server Error',
};
}
}
Submitted by hugo697 412 days ago