Shipping price

  • Posts: 75
  • Thank you received: 4
1 year 1 month ago #356527

-- HikaShop version -- : 4.7.4
-- Joomla version -- : 4.4.0
-- PHP version -- : 8.1

Hello,
I would like to make a dynamic shipping plugin which connect to the shipping company through an API, send there the number and size of packages and get back a shipping price.

My question is how I can implement this funuctionality to a one page checkout page.

So the shipping price will be depends on the customers address. If the customer fill up the address and country I would need to run the API query to get the shipping price.
Which funcion can I use for this? Or should I add a custom button like "Calculate shipping" and runu my function on click?

What I need to modify to add the calculated shipping price to the cart?

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
1 year 1 month ago #356529

Hi,

Well, let's first talk about the current situation of the HikaShop checkout and shipping.

HikaShop already comes with several shipping plugins which connect to a shipping company through an API providing the address of the user, the number and size of packages, etc and get back the shipping fee. You can find these in the folder plugins/hikashopshipping/ of your website. I would recommend looking at the ups2 one, which is the latest we developed, and the cleanest, but it's only there if you have HikaShop 5.0.0 installed.

You can also have a one page checkout with HikaShop (the checkout is actually configured as a one page checkout by default).
However, if you have a shipping method for a plugin which requires the address of the user to calculate the shipping fee, like these plugins, the customer will have to first validate the guest shipping address so that the shipping fees can be updated before finishing the checkout.

Finally, note that our marketplace also has a shipping estimation plugin available here:
www.hikashop.com/marketplace/product/244...tion-by-obsidev.html
With it, you can allow customers to directly pre caclulate their shipping fee for a particular product even before they have it in the cart, or provided their full address. The plugin will just ask the customer for the necessary information (like the post code and the country) to be able to retrieve the information.

Please Log in or Create an account to join the conversation.

  • Posts: 75
  • Thank you received: 4
1 year 4 weeks ago #356973

I made a multi step cart, connected to shipping company API inside the onShippingDisplay.
I have the API response, and saved the shipping price in a variable $shippingPrice

How can I display this price next to the shipping method name and add this value as shipping price before the customer pays.
Looks like it's a one last step, but can't figure it out.

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
1 year 4 weeks ago #356977

Hi,

In the parameters of the onShippingDisplay method, you have the parameters $methods and $usable_methods

onShippingDisplay(&$order,&$methods,&$usable_methods,&$messages)
In $methods you have all the shipping methods prefiltered by HikaShop.
In $usable_methods you have an empty array.
So what you need to do is to make a copy of your shipping method data from $methods, overwrite the shipping_price with the fee retrieved from your shipping company and then add that copy in $usable_methods so that HikaShop can use it as an available shipping method on the checkout.

The following user(s) said Thank You: Petike1007

Please Log in or Create an account to join the conversation.

Time to create page: 0.062 seconds
Powered by Kunena Forum