1

I'm using woocommerce and dokan as multi vendor shipping. i want to calculate rates to external API by passing those vendors address.

for example: I have vendor A and B. the customer address is C. when I calculate rate it still show the same price. it sould display different result. price from A -> C 3000 and B -> C 4000 (based on external API testing). this is the code to calculate it

...
public function calculate_shipping($package = array())
{
 $bodyArr = [
    'origin' => [
        "address" => WC()->countries->get_base_address(),
        "province" =>  WC()->countries->get_base_state(),
        "city" => WC()->countries->get_base_city(),
        "zip_code" => WC()->countries->get_base_postcode()
    ],
    "destination" => [
        "address" => $package['destination']['address'],
        "province" => $package['destination']['state'],
        "city" => $package['destination']['city'],
        "zip_code" => $package['destination']['postcode']
    ]
 ];

 //call external API by passing the body request
 $response = function_to_call_api($bodyRequest);

 //assume the response is success
 foreach($response['details'] as $key => $detail){
   $this->add_rate([
     'id' => $key + 1,
     'label' => $detail['service_name'],
     'cost' => $detail['price'],
   ], $package);

 }

}
...

how to call api external based on product ordered (vendor's product) to calculate rates?

catLovers
  • 41
  • 7

0 Answers0