我正在为woocommerce批发销售手机的客户开发一个主题。客户端在mobileshop.bz上有一个帐户,他们有自己的系统,名为NATM。我可以进口的产品真的很容易,但我需要找到一种方式,从我的客户网站发送订单细节到他的帐户上移动。
似乎我必须先预订文章,然后创建一个销售订单,这个家伙在mobileshop为我提供了这段代码片段,以保留一篇文章
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restful.mobileshop.bz/reserveArticle/new/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array('sku' => '','qty' => ''),
CURLOPT_HTTPHEADER => array(
"Authorization: paste in your API key"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;这是给createSalesOrder的
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://restful.mobileshop.bz/createSalesOrder/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array('reservation[]' => '','reservation[]' => '','pay_method' => '','insurance' => '','drop_shipping' => '0','drop_ship[name]' => '','drop_ship[address]' => '','drop_ship[postcode]' => '','drop_ship[city]' => '','drop_ship[country]' => '','drop_ship[contact]' => ''),
CURLOPT_HTTPHEADER => array(
"Authorization: paste in your API key"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;我只是问如何将它集成到我的自定义主题本身,是否修改代码示例并将其添加到我的functions.php文件中。
非常感谢,菲利普·露丝
发布于 2020-07-23 21:47:02
如果您希望在每一个订单上启动它,请使用一个WooCommerces钩子并将其放置到您的functions.php文件中。
add_action( 'woocommerce_thankyou', 'so_woocommerce_thankyou' );
function so_woocommerce_thankyou( $order_id ) {
$Order = new WP_Order( $order_id );
// Build your item sku and qty array
$payloadItems = [];
foreach( $Order->get_items() as $item ) {
$product = wc_get_product( $item->get_product_id );
$payloadItems[] = [$product->get_sku(), $item->get_quantity()];
}
// Reserve
$reservations = [];
if( count( $payloadItems ) ) {
foreach( $payloadItems as $item ) {
$reservations[] = reserveArticle( $item[0], $item[1] );
}
}
// Send sales order
$salesOrder = false;
if( count( $reservations ) ) {
$salesOrder = sendSalesOrder( $Order, $reservations );
}
if( $salesOrder !== false ) {
// Success
} else {
// Something went wrong
}
}
function reserveArticle( $sku, $qty ) {
// The cURL request to reserve an article.
// Pipe in the required information into your postfields value return response
}
function sendSalesOrder( $reservation, $Order ) {
// The cURL request to send a sales order.
// Pipe in the required information into your postfields value return response or false on error
}我就是这样接近它的。可能需要根据特定需求和任何错误进行调整,因为它完全没有经过测试。
发布于 2020-07-23 00:07:28
我可以从两方面看出这是一个整体。
form.
时丢弃它们。
这不是一个具体的想法,但希望它能给你提供如何处理它的想法。
https://stackoverflow.com/questions/62967013
复制相似问题