Я пытаюсь создать функции API для Mobile, чтобы получить методы доставки от WordPress WooCommerce. Это мой код: < /p>
public function get_shipping($request){
$params = (array) json_decode(file_get_contents('php://input'), TRUE);
$state = $params['state'];
$country = $params['country'];
global $woocommerce;
$woocommerce->cart->empty_cart();
foreach ($params['line_items'] as $item) {
if((int) $item["variation_id"] > 0 ){
$woocommerce->cart->add_to_cart(
(int) $item["id"],
(int) $item["quantity"],
$item["variation_id"]);
} else {
$woocommerce->cart->add_to_cart(
(int) $item["id"],
(int) $item["quantity"]);
}
}
$package = $woocommerce->cart->get_shipping_packages();
$delivery_zones = (Array) WC_Shipping_Zones::get_zones();
$new_delivery_zones = Array();
foreach ($delivery_zones as $zone) {
$z_object = (Array) $zone;
$new_shippings = Array();
foreach ($z_object["shipping_methods"] as $shipping) {
$s_item = Array();
$objects = (Array) $shipping;
foreach ($objects as $key => $value) {
if($key != "instance_form_fields") {
$s_item[$key] = $value;
}else{
$f_item = Array();
$new_form_fields = Array();
$form_fields = (Array) $value;
foreach ($form_fields as $keyi => $valuei) {
$valuei["name"] = $keyi;
$f_item[$keyi] = $valuei;
array_push($new_form_fields, $valuei);
}
$s_item["instance_form_fields"] = $new_form_fields;
}
}
array_push($new_shippings, $s_item);
}
$z_object["shipping_methods"] = null;
$z_object["shipping_methods"] = $new_shippings;
array_push($new_delivery_zones, $z_object);
}
$correct_zone = null;
foreach ($new_delivery_zones as $zone) {
foreach ($zone["zone_locations"] as $location) {
$splits = explode(":",$location-> code);
if(count($splits) > 1){
$country = $splits[0];
$code = $splits[1];
if($country == $country && $code == $state ){
$correct_zone = $zone;
}
}
}
}
if($correct_zone == null)
return $correct_zone;
$package['destination']['country'] = $country;
$package['destination']['state'] = (int) $state;
$package['destination']['country'] = $country;
$new_shipping_method = Array();
foreach ($correct_zone["shipping_methods"] as $shipping_method) {
if (class_exists($shipping_method["id"])) {
$class = new $shipping_method["id"]();
$class->calculate_shipping_for_package($package);
foreach ($class->rates as $rate) {
array_push($shipping_method["rates"], Array(
"cost" => $rate->cost,
"label" => $rate->label,
"method_id" => $rate->method_id
));
}
// error_log(print_r($class->rates, true));
array_push($new_shipping_method, $shipping_method);
}else{
array_push($new_shipping_method, $shipping_method);
}
}
$correct_zone["shipping_methods"] = $new_shipping_method;
return $correct_zone;
}
< /code>
и я читаю этот пост < /p>
Но я не понял, где проблема, потому что она делает Не работайте должным образом, и его рассчитанные цены не соответствуют плагинам Post.>
Подробнее здесь: https://stackoverflow.com/questions/500 ... ulated-api
WooCommerce Получить весь метод доставки рассчитанного API ⇐ Php
Кемеровские программисты php общаются здесь
-
Anonymous
1740448488
Anonymous
Я пытаюсь создать функции API для Mobile, чтобы получить методы доставки от WordPress WooCommerce. Это мой код: < /p>
public function get_shipping($request){
$params = (array) json_decode(file_get_contents('php://input'), TRUE);
$state = $params['state'];
$country = $params['country'];
global $woocommerce;
$woocommerce->cart->empty_cart();
foreach ($params['line_items'] as $item) {
if((int) $item["variation_id"] > 0 ){
$woocommerce->cart->add_to_cart(
(int) $item["id"],
(int) $item["quantity"],
$item["variation_id"]);
} else {
$woocommerce->cart->add_to_cart(
(int) $item["id"],
(int) $item["quantity"]);
}
}
$package = $woocommerce->cart->get_shipping_packages();
$delivery_zones = (Array) WC_Shipping_Zones::get_zones();
$new_delivery_zones = Array();
foreach ($delivery_zones as $zone) {
$z_object = (Array) $zone;
$new_shippings = Array();
foreach ($z_object["shipping_methods"] as $shipping) {
$s_item = Array();
$objects = (Array) $shipping;
foreach ($objects as $key => $value) {
if($key != "instance_form_fields") {
$s_item[$key] = $value;
}else{
$f_item = Array();
$new_form_fields = Array();
$form_fields = (Array) $value;
foreach ($form_fields as $keyi => $valuei) {
$valuei["name"] = $keyi;
$f_item[$keyi] = $valuei;
array_push($new_form_fields, $valuei);
}
$s_item["instance_form_fields"] = $new_form_fields;
}
}
array_push($new_shippings, $s_item);
}
$z_object["shipping_methods"] = null;
$z_object["shipping_methods"] = $new_shippings;
array_push($new_delivery_zones, $z_object);
}
$correct_zone = null;
foreach ($new_delivery_zones as $zone) {
foreach ($zone["zone_locations"] as $location) {
$splits = explode(":",$location-> code);
if(count($splits) > 1){
$country = $splits[0];
$code = $splits[1];
if($country == $country && $code == $state ){
$correct_zone = $zone;
}
}
}
}
if($correct_zone == null)
return $correct_zone;
$package['destination']['country'] = $country;
$package['destination']['state'] = (int) $state;
$package['destination']['country'] = $country;
$new_shipping_method = Array();
foreach ($correct_zone["shipping_methods"] as $shipping_method) {
if (class_exists($shipping_method["id"])) {
$class = new $shipping_method["id"]();
$class->calculate_shipping_for_package($package);
foreach ($class->rates as $rate) {
array_push($shipping_method["rates"], Array(
"cost" => $rate->cost,
"label" => $rate->label,
"method_id" => $rate->method_id
));
}
// error_log(print_r($class->rates, true));
array_push($new_shipping_method, $shipping_method);
}else{
array_push($new_shipping_method, $shipping_method);
}
}
$correct_zone["shipping_methods"] = $new_shipping_method;
return $correct_zone;
}
< /code>
и я читаю этот пост < /p>
Но я не понял, где проблема, потому что она делает Не работайте должным образом, и его рассчитанные цены не соответствуют плагинам Post.>
Подробнее здесь: [url]https://stackoverflow.com/questions/50016822/woocommerce-get-all-shiping-method-calculated-api[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия