News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Programatically pre-set shipping method?

Started by vmfyelloq19, July 25, 2024, 20:30:52 PM

Previous topic - Next topic

vmfyelloq19

Friends,

I'd like so pre-set a shipping method (based on some very specific conditions not imporatnt here).
The idea is that the shipping method is pre-set when the customers checks out, while still allowing to change it.

I have prepared a system plugin for this but I have trouble selecting the proper event.
Several events looked promising, like plgVmOnSelectedCalculatePriceShipment(), but I could not get it to work by now.

Any hints?

Jumbo!

You may want to consider using the "plgVmOnCheckoutCheckStock" event. In this event, the first argument passed is the cart object, which you can use to modify the "virtuemart_shipmentmethod_id" property. Remember not to return anything in the listener function.

Also, keep in mind that a system plugin in Joomla 4 and 5 won't listen to events that do not start with the "on" prefix. To address this, you can add the following function in the plugin's constructor to listen to the "plgVmOnCheckoutCheckStock" event.

$this->registerLegacyListener('plgVmOnCheckoutCheckStock');

vmfyelloq19

Hi Jumbo,

thank you for your suggestion. I was under the impression I could not change the cart from here but re-checking after your post shows it does just fine. Seems One Page Checkout byPV is ignoring my changes. So I might need to investigate there (or drop OPC completely, as I'd probalby do for other reasons anyway)

Thanks again!