У меня есть магазин woo-commerce и платформа для отправки трески для доставки моих продуктов покупателю.Мне нужно добавить заказ клиента в ХПК через веб-сервис
в файле function.php моей темы, я сделал это сейчас, но этот скрипт просто добавляет один из продуктов клиента в заказ, который мне нужно отправить всемпродукты в веб-сервисе
$hook_to = 'woocommerce_thankyou';
$what_to_hook = 'add2postweb';
$prioriy = 111;
$num_of_arg = 1;
add_action($hook_to, $what_to_hook, $prioriy, $num_of_arg);
function add2postweb($order_id){
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
$order_data = $order->get_data(); // The Order data
$order_payment_method = $order_data['payment_method'];
$order_billing_first_name = $order_data['billing']['first_name'];
$order_billing_last_name = $order_data['billing']['last_name'];
$order_billing_company = $order_data['billing']['company'];
$order_billing_address_1 = $order_data['billing']['address_1'];
$order_billing_address_2 = $order_data['billing']['address_2'];
$order_billing_city = $order_data['billing']['city'];
$order_billing_state = $order_data['billing']['state'];
$order_billing_postcode = $order_data['billing']['postcode'];
$order_billing_country = $order_data['billing']['country'];
$order_billing_email = $order_data['billing']['email'];
$order_billing_phone = $order_data['billing']['phone'];
$stuff_id=array();
$stuff_count=array();
// Iterating through each WC_Order_Item_Product objects
foreach ($order->get_items() as $item_key => $item_values):
## Access Order Items data properties (in an array of values) ##
$item_data = $item_values->get_data();
$product_name = $item_data['name'];
$product_id = $item_data['product_id'];
$variation_id = $item_data['variation_id'];
$quantity = $item_data['quantity'];
$tax_class = $item_data['tax_class'];
$line_subtotal = $item_data['subtotal'];
$line_subtotal_tax = $item_data['subtotal_tax'];
$line_total = $item_data['total'];
$line_total_tax = $item_data['total_tax'];
$username = '*******';
$password = '*******';
$client = new SoapClient('http://svc.ebazaar-post.ir/EshopService.svc?wsdl');
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
$result = $client -> AddStuff ([
'username' => $username,
'password' => $password,
'name' => $product_name,
'price' => 501111000,
'weight' => 2010,
'count' => 1100,
'description' => 'تست',
'percentDiscount' => 0,
]);
$stuff_id=(int)$result->AddStuffResult;
$count=(int)$quantity;
endforeach;
echo'<<<<<<<<<<';
echo $stuff_id;
echo $count;
echo '>>>>>>>>>>';
$username = 'borujerd';
$password = 'Borujerd20#$';
$client = new SoapClient('http://svc.ebazaar-post.ir/EshopService.svc?wsdl');
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
$result2 = $client -> AddParcel ([
'username' => $username,
'password' => $password,
'productsId' => [
[
'Id' => $stuff_id, // Product id in ebazaar
'Count' => $count, // Request Number Of Product
'DisCount' => 0 // No Discount
]
],
'cityCode' => 1,
'serviceType' => 1, // pishtaz
'payType' => 1,
'registerFirstName' => $order_billing_first_name,
'registerLastName' => $order_billing_last_name,
'registerAddress' => 'نشانی دریافت کننده',
'registerPhoneNumber' => '0912111111',
'registerMobile' => '0912111111',
'registerPostalCode' => '1648853978'
]);
}