[Skip to main content](#vessel-content)

#   Display cheapest shipping method from same carrier

##

- **[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")**
- [![deuce4884's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/38332-deuce4884 "View deuce4884's Profile") Topic Author
- [ Offline](/forum/user/38332-deuce4884)

Less More

- Posts: 128
- Thank you received: 3
-
-

10 years 7 months ago -  10 years 7 months ago [\#234191](#234191) by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")  *[Display cheapest shipping method from same carrier](/forum/28-shipping-methods/883322-display-cheapest-shipping-method-from-same-carrier#234191 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.24  I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.  I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?")* was created by *[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")*

-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.3.24

I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.

[ ![checkout&#95;2016-03-24.png](/forum/attachment/30288) ](/forum/attachment/30288 "...2016-03-24.png")

I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?

- [ ![checkout&#95;2016-03-24.png](/forum/attachment/30288) ](/forum/attachment/30288 "...2016-03-24.png") [ ](/forum/attachment/30288?download=1 "...2016-03-24.png")

Last edit: 10 years 7 months ago by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODgzMzIyLWRpc3BsYXktY2hlYXBlc3Qtc2hpcHBpbmctbWV0aG9kLWZyb20tc2FtZS1jYXJyaWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

10 years 7 months ago -  10 years 7 months ago [\#234208](#234208) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[Display cheapest shipping method from same carrier](/forum/28-shipping-methods/883322-display-cheapest-shipping-method-from-same-carrier#234208 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.24  I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.  I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?")*

Hello,

The solution will just be to use restrictions like Maximum/Minimum :
- Price
- Weight
- Dimensions
- ..

So that you can filter which shipping method you want to be available and in which situation. So the solution will globally depends on how and when you want your shipping method to be displayed.

Last edit: 10 years 7 months ago by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODgzMzIyLWRpc3BsYXktY2hlYXBlc3Qtc2hpcHBpbmctbWV0aG9kLWZyb20tc2FtZS1jYXJyaWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")**
- [![deuce4884's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/38332-deuce4884 "View deuce4884's Profile") Topic Author
- [ Offline](/forum/user/38332-deuce4884)

Less More

- Posts: 128
- Thank you received: 3
-
-

10 years 7 months ago -  10 years 7 months ago [\#234328](#234328) by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")  Replied by *[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")* on topic *[Display cheapest shipping method from same carrier](/forum/28-shipping-methods/883322-display-cheapest-shipping-method-from-same-carrier#234328 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.24  I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.  I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?")*

I understand the purpose of the restrictions and I'm using all of them on all 3 shipping methods. However, the because of the different dimensions, different weights, my shipping box dimensions, and the fact that due to weight limits on carrier services I have some overlap on the restrictions of the shipping methods. I added some javascript to the checkout-&gt;shipping view as a way to try to just hide the more expensive prices of the same methods.
Code:

$js = " //function to only show cheapest carrier rates if overlap function findMinRates(){ var minRates = []; jQuery('.hikashop_shipping_group').each(function(){ var jQuerythis = jQuery(this); jQuerythis.find('.controls .hika-radio.hikashop_shipping_methods_table tr td input.hikashop_checkout_shipping_radio').each(function(){ var shipType = this.next('label').html(); var shipPrice = this.next('span.hikashop_checkout_shipping_price_full').children('span.hikashop_checkout_shipping_price').html(); shipPrice = parseFloat(shipPrice); if(shipType in minRates){ if(shipPrice &gt; minRates[shipType]){ jQuery('input.hikashop_checkout_shipping_radio[value=\"this.val()\"]').parents('tr[class^=\"row\"]').hide(); } }else{ minRates[shipType]=shipPrice; } }); }); } //function for window ready window.hikashop.ready(function(){findMinRates();}); "; if(!HIKASHOP_PHP5) $doc =&amp; JFactory::getDocument(); else $doc = JFactory::getDocument(); $doc-&gt;addScriptDeclaration("\n&lt;!--\n".$js."\n//--&gt;\n");

I'm not getting any results with this though. Am I on the right track with this or is there a way to do what I need to do directly in the php code of the view?

Last edit: 10 years 7 months ago by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODgzMzIyLWRpc3BsYXktY2hlYXBlc3Qtc2hpcHBpbmctbWV0aG9kLWZyb20tc2FtZS1jYXJyaWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86555
- Thank you received: 14304
-
-

10 years 7 months ago [\#234365](#234365) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Display cheapest shipping method from same carrier](/forum/28-shipping-methods/883322-display-cheapest-shipping-method-from-same-carrier#234365 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.24  I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.  I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?")*

Hi,

You can edit the file "shipping" of the view "checkout" via the menu Display&gt;Views. It's that view file which displays the shipping methods. So there, you can filter the shipping methods the way you want.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODgzMzIyLWRpc3BsYXktY2hlYXBlc3Qtc2hpcHBpbmctbWV0aG9kLWZyb20tc2FtZS1jYXJyaWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")**
- [![deuce4884's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/38332-deuce4884 "View deuce4884's Profile") Topic Author
- [ Offline](/forum/user/38332-deuce4884)

Less More

- Posts: 128
- Thank you received: 3
-
-

10 years 7 months ago [\#234379](#234379) by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")  Replied by *[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")* on topic *[Display cheapest shipping method from same carrier](/forum/28-shipping-methods/883322-display-cheapest-shipping-method-from-same-carrier#234379 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.24  I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.  I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?")*

I think I got this figured out. I found the code:
Code:

foreach($this-&gt;rates as $rate) {

and replaced with:
Code:

$min_rates = array(); foreach($this-&gt;rates as $rate) { if(array_key_exists($rate-&gt;shipping_name,$min_rates)){ if($rate-&gt;shipping_price &lt; $min_rates[$rate-&gt;shipping_name]){ $min_rates[$rate-&gt;shipping_name]= $rate-&gt;shipping_price; }else{ continue; } }else{ $min_rates[$rate-&gt;shipping_name]= $rate-&gt;shipping_price; }

This seems to only show the cheapest shipping method for each carrier if there is any overlap on the restrictions. Do you see any problems that this code could cause? As far as I can tell it's working.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODgzMzIyLWRpc3BsYXktY2hlYXBlc3Qtc2hpcHBpbmctbWV0aG9kLWZyb20tc2FtZS1jYXJyaWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86555
- Thank you received: 14304
-
-

10 years 7 months ago [\#234385](#234385) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Display cheapest shipping method from same carrier](/forum/28-shipping-methods/883322-display-cheapest-shipping-method-from-same-carrier#234385 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.24  I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.  I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?")*

Hi,

It's not ideal but it's ok. Ideally, you should do a first foreach on $this-&gt;rates to construct your own filters list of rates and then replace $this-&gt;rates with your list and then leave the second foreach do it's job on that filtered list.
Because right now with your code, if the first encountered rate has a higher price than the second rate with the same name, you'll actually see both displayed. You're lucky that they are being displayed in the order that works ![:)](/media/kunena/emoticons/3.png ":)")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODgzMzIyLWRpc3BsYXktY2hlYXBlc3Qtc2hpcHBpbmctbWV0aG9kLWZyb20tc2FtZS1jYXJyaWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")**
- [![deuce4884's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/38332-deuce4884 "View deuce4884's Profile") Topic Author
- [ Offline](/forum/user/38332-deuce4884)

Less More

- Posts: 128
- Thank you received: 3
-
-

10 years 7 months ago [\#234437](#234437) by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")  Replied by *[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")* on topic *[Display cheapest shipping method from same carrier](/forum/28-shipping-methods/883322-display-cheapest-shipping-method-from-same-carrier#234437 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.24  I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.  I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?")*

I tried working on this by adding an extra foreach like you mentioned, but I'm losing something. I've not done anything quite like this before. This is what I have now:
Code:

$min_rates = array(); foreach($this-&gt;rates as $min_rate) { if(array_key_exists($min_rate-&gt;shipping_name,$min_rates)){ if($min_rate-&gt;shipping_price &lt; $min_rates[$min_rate-&gt;shipping_name]){ $min_rates[$min_rate-&gt;shipping_name]= $min_rate-&gt;shipping_price; }else{ continue; } }else{ $min_rates[$min_rate-&gt;shipping_name]= $min_rate-&gt;shipping_price; } foreach($min_rates as $rate) { ......existing code

I then added a closing } for the extra foreach after:
Code:

&lt;div class="hikashop_checkout_shipping_description"&gt;&lt;?php echo $rate-&gt;shipping_description;?&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php $k = 1-$k; } } //added this closing for extra foreach

Now nothing is showing. I believe it has something to do with I'm losing values through the first foreach. Can you help me fix this?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODgzMzIyLWRpc3BsYXktY2hlYXBlc3Qtc2hpcHBpbmctbWV0aG9kLWZyb20tc2FtZS1jYXJyaWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86555
- Thank you received: 14304
-
-

10 years 7 months ago [\#234438](#234438) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Display cheapest shipping method from same carrier](/forum/28-shipping-methods/883322-display-cheapest-shipping-method-from-same-carrier#234438 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.24  I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.  I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?")*

Hi,

You've added the second foreach instead the first one. What I was saying was to have two separate foreach one after the other.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODgzMzIyLWRpc3BsYXktY2hlYXBlc3Qtc2hpcHBpbmctbWV0aG9kLWZyb20tc2FtZS1jYXJyaWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")**
- [![deuce4884's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/38332-deuce4884 "View deuce4884's Profile") Topic Author
- [ Offline](/forum/user/38332-deuce4884)

Less More

- Posts: 128
- Thank you received: 3
-
-

10 years 7 months ago [\#234515](#234515) by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")  Replied by *[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")* on topic *[Display cheapest shipping method from same carrier](/forum/28-shipping-methods/883322-display-cheapest-shipping-method-from-same-carrier#234515 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.3.24  I have created 3 UPS shipping methods with varying restrictions because of some of my products' dimensions, products' weights, and shipping box dimensions. When adding different products sometimes I have shipping methods overlap, which means I have 2 UPS shipping methods display for the order.  I'm going to have Fedex methods with the same restrictions, so I'll have the same problem with them. I was wanting to know if there is a way to only return the cheapest method from each carrier?")*

I reworked my code to the following:
Code:

$min_rates = array(); foreach($this-&gt;rates as $min_rate) { if(array_key_exists($min_rate-&gt;shipping_name,$min_rates)){ if($min_rate-&gt;shipping_price &lt; $min_rates[$min_rate-&gt;shipping_name]-&gt;shipping_price){ $min_rates[$min_rate-&gt;shipping_name]= $min_rate; }else{ continue; } }else{ $min_rates[$min_rate-&gt;shipping_name]= $min_rate; } } foreach($min_rates as $rate) { .......existing code

I believe I have it working correctly now. I switched the order of the shipping plugins and added a new cheaper plugin with some of the same restrictions and it seems to be retrieving the cheapest of each method for each carrier now.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODgzMzIyLWRpc3BsYXktY2hlYXBlc3Qtc2hpcHBpbmctbWV0aG9kLWZyb20tc2FtZS1jYXJyaWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.115 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
