Login
Register

VirtueMart

WooCommerce

Others

Docs

Support

Blog

About

Shipping by Rules for VirtueMart

IMPORTANT ANNOUNCEMENT: Plugin development ceased, all plugins made available freely (GPL)

With great sadness we have to announce that we are ceasing development of all our VirtueMart, WooCommerce and Joomla plugins. Effective immediately, all our plugins -- even those that were paid downloads -- are made available for free from our homepage (GPL license still applies), but we cannot and will not provide any support anymore.

It has been a great pleasure to be part of the thriving development communities of VirtueMart as well as WooCommerce. However, during the last year it became painstakingly clear that in addition to a full-time job, a young family and several other time-consuming hobbies at professional level (like being a professional singer) the plugin development and the support that it requires is not sustainable and is taking its toll. It has been an honor, but it is now time to say good bye!

×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Shipping cost based on state/region 27 Dec 2016 17:38 #1

  • fatenrafie
  • fatenrafie's Avatar Topic Author
Hello there,

Greetings from Malaysia.

I need to create three different shipping rates based on the zones of the states. Of the 16 states that we have in Malaysia, 14 will go into one zone/region while the other 2 will go into one each. I've created the rules for all three, but how do I assign them based on zone/region. By the way, when I manually added the states for the country, I couldn't access the zone dropdown menu.

Thanks

Shipping cost based on state/region 28 Dec 2016 10:34 #2

  • fatenrafie
  • fatenrafie's Avatar Topic Author
I've worked out the two odd states and the below codes work

Name=Shipping to Sarawak; State=="Sarawak"; 1<Weight<=1.25; Shipping=19
Name=Shipping to Sabah; State=="Sabah"; 1<Weight<=1.25; Shipping=21

However, for the remaining 14 states, I've tried the code below, but it doesn't work.

Name=Shipping Within Semenanjung; State=="Johor"; "Perak"; "Kedah"; "Kelantan"; "Perlis"; "Pahang"; "Melaka"; "Selangor"; "Putrajaya"; "Pulau Pinang"; "Terengganu"; "Negeri Sembilan"; "Kuala Lumpur";1<Weight<=1.25; Shipping=12

Shipping cost based on state/region 28 Dec 2016 15:34 #3

Dear Fatenrafie,
I think the easiest approach is to handle the two special states first (all weight ranges) and in all rules after that you can assume that the state is none of these two:
Name=Shipping to Sarawak; State=="Sarawak"; Weight<=1; Shipping=1111
Name=Shipping to Sarawak; State=="Sarawak"; 1<Weight<=1.25; Shipping=19
Name=Shipping to Sarawak; State=="Sarawak"; 1.25<Weight; Shipping=2222
Name=Shipping to Sabah; State=="Sabah"; Weight<=1; Shipping=1111
Name=Shipping to Sabah; State=="Sabah"; 1<Weight<=1.25; Shipping=21
Name=Shipping to Sabah; State=="Sabah"; 1.25<Weight; Shipping=2222

Name=Shipping Within Semenanjung; 1<Weight<=1.25; Shipping=12 

Notice that for Sarawak or Sabah one of the first six rules always matches (if you have more fine-grained dependencies on the weight, simply use more than those three rules). As the plugin always uses the first rule that matches, whenever the seventh rule ("Shipping Within Semenanjung") is even considered by the plugin, you can be sure that the state is not Sarawak or Sabah, so you don't have to check that any more. You just need to make sure that any order from Sarawak or Sabah will really match the first few rules.

If you really want to check whether the state is one of the remaining 14 states, you need to use the advanced (paid) version and check whether the state variable is in a list of state names, i.e. something like the following rule:
Name=Shipping Within Semenanjung; State in list("Johor", "Perak", "Kedah", "Kelantan", "Perlis", "Pahang", "Melaka", "Selangor", "Putrajaya", "Pulau Pinang", "Terengganu", "Negeri Sembilan", "Kuala Lumpur");1<Weight<=1.25; Shipping=12 

BTW, using the State variable is not recommended if you want to make a multilingual shop, as that variable might be translated. I would always use the State2 or State3 variables, which are the two- and three-letter codes for the state.

Best regards,
Reinhold

Shipping cost based on state/region 28 Dec 2016 16:25 #4

  • fatenrafie
  • fatenrafie's Avatar Topic Author
I've completed the Sarawak and Sabah

Name=Shipping to Sarawak; State=="Sarawak"; Weight<=0.5; Shipping=12
Name=Shipping to Sarawak; State=="Sarawak"; .05<Weight<=0.75; Shipping=14
Name=Shipping to Sarawak; State=="Sarawak"; 0.75<Weight<=1; Shipping=16.5
Name=Shipping to Sarawak; State=="Sarawak"; 1<Weight<=1.25; Shipping=19
Name=Shipping to Sarawak; State=="Sarawak"; 1.25<Weight<=1.5; Shipping=21.5
Name=Shipping to Sarawak; State=="Sarawak"; 1.5<Weight<=1.75; Shipping=24
Name=Shipping to Sarawak; State=="Sarawak"; 1.75<Weight<=2; Shipping=26.5
Name=Shipping to Sarawak; State=="Sarawak"; 2<Weight<=2.5; Shipping=42
Name=Shipping to Sarawak; State=="Sarawak"; 2.5<Weight<=3; Shipping=47
Name=Shipping to Sarawak; State=="Sarawak"; 3<Weight<=3.5; Shipping=52
Name=Shipping to Sarawak; State=="Sarawak"; 3.5<Weight<=4; Shipping=57
Name=Shipping to Sarawak; State=="Sarawak"; 4<Weight<=4.5; Shipping=62
Name=Shipping to Sarawak; State=="Sarawak"; 4.5<Weight<=5; Shipping=67
Name=Shipping to Sarawak; State=="Sarawak"; 5<Weight<=5.5; Shipping=72
Name=Shipping to Sarawak; State=="Sarawak"; 5.5<Weight<=6; Shipping=77
Name=Shipping to Sarawak; State=="Sarawak"; 6<Weight<=6.5; Shipping=82
Name=Shipping to Sarawak; State=="Sarawak"; 6.5<Weight<=7; Shipping=87
Name=Shipping to Sarawak; State=="Sarawak"; 7<Weight<=7.5; Shipping=92
Name=Shipping to Sarawak; State=="Sarawak"; 7.5<Weight<=8; Shipping=97
Name=Shipping to Sarawak; State=="Sarawak"; 8<Weight<=8.5; Shipping=102
Name=Shipping to Sarawak; State=="Sarawak"; 8.5<Weight<=9; Shipping=107
Name=Shipping to Sarawak; State=="Sarawak"; 9<Weight<=9.5; Shipping=112
Name=Shipping to Sarawak; State=="Sarawak"; 9.5<Weight<=10; Shipping=117
Name=Shipping to Sarawak; State=="Sarawak"; 10<Weight<=11; Shipping=130
Name=Shipping to Sarawak; State=="Sarawak"; 11<Weight<=12; Shipping=140
Name=Shipping to Sarawak; State=="Sarawak"; 12<Weight<=13; Shipping=150
Name=Shipping to Sarawak; State=="Sarawak"; 13<Weight<=14; Shipping=160
Name=Shipping to Sarawak; State=="Sarawak"; 14<Weight<=15; Shipping=170
Name=Shipping to Sarawak; State=="Sarawak"; 15<Weight<=16; Shipping=180
Name=Shipping to Sarawak; State=="Sarawak"; 16<Weight<=17; Shipping=190
Name=Shipping to Sarawak; State=="Sarawak"; 17<Weight<=18; Shipping=200
Name=Shipping to Sarawak; State=="Sarawak"; 18<Weight<=19; Shipping=210
Name=Shipping to Sarawak; State=="Sarawak"; 19<Weight<=20; Shipping=220
Name=Shipping to Sarawak; State=="Sarawak"; 20<Weight<=21; Shipping=230
Name=Shipping to Sarawak; State=="Sarawak"; 21<Weight<=22; Shipping=240
Name=Shipping to Sarawak; State=="Sarawak"; 22<Weight<=23; Shipping=250
Name=Shipping to Sarawak; State=="Sarawak"; 23<Weight<=24; Shipping=260
Name=Shipping to Sarawak; State=="Sarawak"; 24<Weight<=25; Shipping=270

Name=Shipping to Sabah; State=="Sabah"; Weight<=0.5; Shipping=13
Name=Shipping to Sabah; State=="Sabah"; 0.5<Weight<=0.75; Shipping=15
Name=Shipping to Sabah; State=="Sabah"; 0.75<Weight<=1; Shipping=18
Name=Shipping to Sabah; State=="Sabah"; 1<Weight<=1.25; Shipping=21
Name=Shipping to Sabah; State=="Sabah"; 1.25<Weight<=1.5; Shipping=24
Name=Shipping to Sabah; State=="Sabah"; 1.5<Weight<=1.75; Shipping=27
Name=Shipping to Sabah; State=="Sabah"; 1.75<Weight<=2; Shipping=30
Name=Shipping to Sabah; State=="Sabah"; 2<Weight<=2.5; Shipping=42
Name=Shipping to Sabah; State=="Sabah"; 2.5<Weight<=3; Shipping=47
Name=Shipping to Sabah; State=="Sabah"; 3<Weight<=3.5; Shipping=52
Name=Shipping to Sabah; State=="Sabah"; 3.5<Weight<=4; Shipping=57
Name=Shipping to Sabah; State=="Sabah"; 4<Weight<=4.5; Shipping=62
Name=Shipping to Sabah; State=="Sabah"; 4.5<Weight<=5; Shipping=67
Name=Shipping to Sabah; State=="Sabah"; 5<Weight<=5.5; Shipping=72
Name=Shipping to Sabah; State=="Sabah"; 5.5<Weight<=6; Shipping=77
Name=Shipping to Sabah; State=="Sabah"; 6<Weight<=6.5; Shipping=82
Name=Shipping to Sabah; State=="Sabah"; 6.5<Weight<=7; Shipping=87
Name=Shipping to Sabah; State=="Sabah"; 7<Weight<=7.5; Shipping=92
Name=Shipping to Sabah; State=="Sabah"; 7.5<Weight<=8; Shipping=97
Name=Shipping to Sabah; State=="Sabah"; 8<Weight<=8.5; Shipping=102
Name=Shipping to Sabah; State=="Sabah"; 8.5<Weight<=9; Shipping=107
Name=Shipping to Sabah; State=="Sabah"; 9<Weight<=9.5; Shipping=112
Name=Shipping to Sabah; State=="Sabah"; 9.5<Weight<=10; Shipping=117
Name=Shipping to Sabah; State=="Sabah"; 10<Weight<=11; Shipping=130
Name=Shipping to Sabah; State=="Sabah"; 11<Weight<=12; Shipping=140
Name=Shipping to Sabah; State=="Sabah"; 12<Weight<=13; Shipping=150
Name=Shipping to Sabah; State=="Sabah"; 13<Weight<=14; Shipping=160
Name=Shipping to Sabah; State=="Sabah"; 14<Weight<=15; Shipping=170
Name=Shipping to Sabah; State=="Sabah"; 15<Weight<=16; Shipping=180
Name=Shipping to Sabah; State=="Sabah"; 16<Weight<=17; Shipping=190
Name=Shipping to Sabah; State=="Sabah"; 17<Weight<=18; Shipping=200
Name=Shipping to Sabah; State=="Sabah"; 18<Weight<=19; Shipping=210
Name=Shipping to Sabah; State=="Sabah"; 19<Weight<=19.5; Shipping=220
Name=Shipping to Sabah; State=="Sabah"; 19.5<Weight<=20; Shipping=252
Name=Shipping to Sabah; State=="Sabah"; 20<Weight<=21; Shipping=265
Name=Shipping to Sabah; State=="Sabah"; 21<Weight<=22; Shipping=280
Name=Shipping to Sabah; State=="Sabah"; 22<Weight<=23; Shipping=290
Name=Shipping to Sabah; State=="Sabah"; 23<Weight<=24; Shipping=300
Name=Shipping to Sabah; State=="Sabah"; 24<Weight<=25; Shipping=310

Shipping cost based on state/region 28 Dec 2016 16:28 #5

  • fatenrafie
  • fatenrafie's Avatar Topic Author
As for the 14 states, I've done for each and everyone of them

eg.
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; Weight<=1; Shipping=8
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 1<Weight<=2; Shipping=10
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 2<Weight<=3; Shipping=12
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 3<Weight<=4; Shipping=14
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 4<Weight<=5; Shipping=16
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 5<Weight<=6; Shipping=18
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 6<Weight<=7; Shipping=20
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 7<Weight<=8; Shipping=22
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 8<Weight<=9; Shipping=24
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 9<Weight<=10; Shipping=26
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 10<Weight<=11; Shipping=28
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 11<Weight<=12; Shipping=30
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 12<Weight<=13; Shipping=32
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 13<Weight<=14; Shipping=34
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 14<Weight<=15; Shipping=36
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 15<Weight<=16; Shipping=38
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 16<Weight<=17; Shipping=40
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 17<Weight<=18; Shipping=42
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 18<Weight<=19; Shipping=44
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 19<Weight<=20; Shipping=46
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 20<Weight<=21; Shipping=48
Name=Shipping Within Semenanjung; State=="Pulau Pinang"; 21<Weight<=25; Shipping=50

Name=Shipping Within Semenanjung; State=="Johor"; Weight<=1; Shipping=8
Name=Shipping Within Semenanjung; State=="Johor"; 1<Weight<=2; Shipping=10
Name=Shipping Within Semenanjung; State=="Johor"; 2<Weight<=3; Shipping=12
Name=Shipping Within Semenanjung; State=="Johor"; 3<Weight<=4; Shipping=14
Name=Shipping Within Semenanjung; State=="Johor"; 4<Weight<=5; Shipping=16
Name=Shipping Within Semenanjung; State=="Johor"; 5<Weight<=6; Shipping=18
Name=Shipping Within Semenanjung; State=="Johor"; 6<Weight<=7; Shipping=20
Name=Shipping Within Semenanjung; State=="Johor"; 7<Weight<=8; Shipping=22
Name=Shipping Within Semenanjung; State=="Johor"; 8<Weight<=9; Shipping=24
Name=Shipping Within Semenanjung; State=="Johor"; 9<Weight<=10; Shipping=26
Name=Shipping Within Semenanjung; State=="Johor"; 10<Weight<=11; Shipping=28
Name=Shipping Within Semenanjung; State=="Johor"; 11<Weight<=12; Shipping=30
Name=Shipping Within Semenanjung; State=="Johor"; 12<Weight<=13; Shipping=32
Name=Shipping Within Semenanjung; State=="Johor"; 13<Weight<=14; Shipping=34
Name=Shipping Within Semenanjung; State=="Johor"; 14<Weight<=15; Shipping=36
Name=Shipping Within Semenanjung; State=="Johor"; 15<Weight<=16; Shipping=38
Name=Shipping Within Semenanjung; State=="Johor"; 16<Weight<=17; Shipping=40
Name=Shipping Within Semenanjung; State=="Johor"; 17<Weight<=18; Shipping=42
Name=Shipping Within Semenanjung; State=="Johor"; 18<Weight<=19; Shipping=44
Name=Shipping Within Semenanjung; State=="Johor"; 19<Weight<=20; Shipping=46
Name=Shipping Within Semenanjung; State=="Johor"; 20<Weight<=21; Shipping=48
Name=Shipping Within Semenanjung; State=="Johor"; 21<Weight<=25; Shipping=50

Shipping cost based on state/region 28 Dec 2016 16:31 #6

  • fatenrafie
  • fatenrafie's Avatar Topic Author
However, when I saved them, all the rules go missing. If I split them up to 2 zones, the second one goes missing, if I do 3 zones, the third one go missing.

Help

Shipping cost based on state/region 07 Jan 2017 14:28 #7

Dear Fatenrafie,
The issue with the config settings going missing when the rules are very long is a known problem in VirtueMart: Each shipping method has a maximum of ~19.000 characters in the database structure to store its configuration. If your rules are long enough to hit that maximum, VirtueMart will fail to write the config to the database, but does not show any warning or error. Even the plugin itself does not get any info/error that the configuration could not properly be saved.
One workaround is to split the rules across several shipping methods or to try to get your rule set smaller/shorter.

Having said that, let's look at your rules:
1. You said that only two provinces have special rates, all other 14 have the same shipping costs. If you place the two special provinces first, you don't have to check all other 14 states any more, so for all remaining states you don't need to duplicate the rules.

2. Looking at your shipping costs, it appears that the advanced (paid) version can significantly simplify/shorten the rules:
Name=Shipping to Sarawak; State=="Sarawak"; Weight<=0.5; Shipping=12
Name=Shipping to Sarawak; State=="Sarawak"; 0.5<Weight<=2; Shipping=11.5+2.5*ceil(4*(Weight-0.5) )
Name=Shipping to Sarawak; State=="Sarawak"; 2<Weight<=10; Shipping=37+5*ceil(2*(Weight-2))
Name=Shipping to Sarawak; State=="Sarawak"; 10<Weight<=25; Shipping=120+10*ceil(Weight-10)

For example, between 0.5kg and 2kg, you charge 2.5 for each 1/4 kg (with 11.5 for the first 0.5kg).
Similarly, between 2kg and 10kg, each 1/2 kg costs 5, while the first 2kg have an offset ot 37 (i.e. 2.2kg have 37 base costs plus 5 first the remaining 0.2kg). Etc.

You can write the rules for Sabah and for the remaining 14 provinces similarly, which should shorten your ruleset significantly and make it easier to check / modify later on.

Best regards,
Reinhold
  • Page:
  • 1