Hide Other Shipping (if free shipping active) plus also hide free shipping if active for a customer Group

448 Views Asked by At

Opencart Version 2.3.0.2 - currently using Vqmod (below) to hide other shipping when free shipping is active. I am looking to adapt it to also hide free shipping for a particular Customer group = '2" (i.e. Wholesale customers will not see\be allowed free shipping).

<file path="catalog/model/extension/shipping/*.php">
<operation error="skip">
<search><![CDATA[if ($status) {]]></search>
<add position="before"><![CDATA[
if (get_class($this)!='ModelExtensionShippingFree') {
if (($this->config->get('free_status') == 1) && (float)$this->cart->getTotal() >= $this->config->get('free_total')) {
$status = false;
}
}
]]></add>

1

There are 1 best solutions below

1
Sumit Wadhwa On

I haven't had a lot of experience with opencart, but AFAIK you don't need to use vqmod for opencart v2.3 or above. Plus, it's performance bottelneck and unpredictable.

The index method of class ControllerCheckoutShippingMethod [ catalog/controller/checkout/shipping_method.php ] is responsible for generating all the shipping methods and putting them all inside the session. Opencart allows us to place an event right after this index method call and modify the final output.

Create a module with the below content inside the install method and whatever else you wanna put it in there:

<?php
// admin/controller/extensions/module/mymodule.php
public function install() {
 $this->load->model('extension/event');
 $this->model_extension_event->addEvent(
      'my_custom_module',
      'catalog/controller/checkout/shipping_method/after', // add event after shipping_method index call
      'extension/module/mymodule/eventAfterSM' // your module file (mymodule.php) with eventAfterSM method in it
 );
}

// catalog/controller/extension/module/mymodule.php
public function eventAfterSM() {
  // this method will be called right after `ControllerCheckoutShippingMethod`->`index`
  // copy and paste the entire index method code in here and modify accordingly
  // and finally set the modified data
  $this->response->setOutput($this->load->view('checkout/payment_method', $data));
}