Allow Free Shipping AND Allow Other Options

Open to all! Ask other shopowners for help.
Post Reply
GetSirius
Member
Posts: 50
Joined: Wed Mar 17, 2021 7:15 pm
Phoenix Version:
Has thanked: 14 times
Been thanked: 2 times

Allow Free Shipping AND Allow Other Options

Post by GetSirius »

Modules > Order Total > Shipping > Allow Free Shipping

Wondering if there is a way to allow for free shipping on orders over some total, but still allow the other shipping options to display. Needed in case a customer would like to pay for a faster shipping option.

Another option would be a way to modify "Flat Rate" to be allowed on orders over some total cost.

Thank you!


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Allow Free Shipping AND Allow Other Options

Post by Kofod95 »

Copy flat shipping, rename yhe references to flat (but don't use underscore in the new name) and add an if statement before return, that checks if the order total is larger than "free shipping".
I think that's the easiest route.

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
GetSirius
Member
Posts: 50
Joined: Wed Mar 17, 2021 7:15 pm
Phoenix Version:
Has thanked: 14 times
Been thanked: 2 times

Re: Allow Free Shipping AND Allow Other Options

Post by GetSirius »

Kofod95 wrote: Mon Sep 16, 2024 8:14 pm Copy flat shipping, rename yhe references to flat (but don't use underscore in the new name) and add an if statement before return, that checks if the order total is larger than "free shipping".
I think that's the easiest route.

//Daniel
Thank you. I got as far as copying the flat shipping module and was able to install it and make it work as a normal flat shipping module. I was then stumped at how to do the if statement. I was unable to figure out how or where to put the if statement.

I'm not a good coder. It seems to me that this new module (like other shipping modules) is not used if shipping is over the set free shipping amount, and that would make the system not even look at my new module.

I would like to pursue this but I will soon be away from my computers for a few days, so any more replies from me may be a while...
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: Allow Free Shipping AND Allow Other Options

Post by heatherbell »

GetSirius wrote: Mon Sep 16, 2024 5:46 pm Wondering if there is a way to allow for free shipping on orders over some total, but still allow the other shipping options to display.
Maybe don't use Allow Free Shipping and instead use Table Rate configured to 'price' and be 0.00 over desired total.
https://github.com/CE-PhoenixCart/Phoen ... le.php#L68
It's just a thought, it might work in some use case scenarios and not others.
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Allow Free Shipping AND Allow Other Options

Post by Kofod95 »

GetSirius wrote: Mon Sep 16, 2024 11:07 pm It seems to me that this new module (like other shipping modules) is not used if shipping is over the set free shipping amount, and that would make the system not even look at my new module.
That's correct and expected. The order total module for free shipping, "overrides" all shipping modules, so you need to set that to false.
What you must do to have several shipping options shown, if which one is free, is to set up your shipping module(s) that way. You have a new module, that's a good first step. Now look at the code. You have two functions. You can add a if-statement in either, but only one is correct - it should be obvious which one. What you want, is to only make the module show, if the order total is higher than the configuration for free shipping. That means you must control when the module returns something to checkout_shipping. You can learn more about the "return" statement by googling, if you want.

You also need to know the order total - some help for that can be found here: https://github.com/CE-PhoenixCart/Phoen ... e.php#L107

I wish you a good trip - and feel free to ask further when you return.

Edit
Or do as Heatherbell suggest...

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Re: Allow Free Shipping AND Allow Other Options

Post by 14Steve14 »

For a few beers I would speak to @burt. Not too sure that he would like me posting his code here or indeed me sharing it with you.

He created for me a module based on flat rate shipping that included a way of setting a maximum and minimum weight and order value. This allows us to switch different shipping methods on or off depending on order weight or total value. This was done as we use Royal mail as a shipping partner and they have funny weight brackets.

You could use the module to only cut in and show over a certain order value or order total, and have a zero shipping cost. You could then copy the module to use as your standard shipping costs but have it not show after a set total weight or order value when the other free module cuts in.

We use multiple copies of this for all of the shipping modules on our site so we can carefully choose which modules show and when they show.

May be worth an ask.
GetSirius
Member
Posts: 50
Joined: Wed Mar 17, 2021 7:15 pm
Phoenix Version:
Has thanked: 14 times
Been thanked: 2 times

Re: Allow Free Shipping AND Allow Other Options

Post by GetSirius »

Thank you. I have this working now. Editing this post to add my code in case someone else is interested. Be aware I am an amateur with php, use this code at your own risk! Just two files, then go to modules/shipping to add module, then edit.

shop/includes/modules/shipping:

Code: Select all

<?php
/*
  $Id$

 Release Date: 22/09/2024
 GetSirius

  Released under the GNU General Public License
*/

  class siriusflat extends abstract_shipping_module {

    const CONFIG_KEY_BASE = 'MODULE_SHIPPING_SIRIUSFLAT_';

// class methods
    public function quote($method = '') {
      global $order;
 
      $this->quotes = [
        'id' => $this->code,
        'module' => MODULE_SHIPPING_SIRIUSFLAT_TEXT_TITLE,
        'methods' => [[
          'id' => $this->code,
          'title' => MODULE_SHIPPING_SIRIUSFLAT_TEXT_WAY,	
          'cost' => (float)$this->base_constant('COST') + $this->calculate_handling(),
        ]],
      ];

      $this->quote_common();

// get order total without including virtual products - UNTESTED FOR VIRTUAL PRODUCTS
      global $order, $currencies;

      $physical_order_total = (('physical' === $order->content_type) ? $_SESSION['cart']->show_total() : 0);

      if ('mixed' === $order->content_type) {
        foreach ($order->products as $product) {
          foreach (($product['attributes'] ?? []) as $option => $value) {
            $virtual_check = $GLOBALS['db']->query(sprintf(<<<'EOSQL'
SELECT COUNT(*) AS total
  FROM products_attributes pa
    INNER JOIN products_attributes_download pad
      ON pa.products_attributes_id = pad.products_attributes_id
  WHERE pa.products_id = %d AND pa.options_values_id = %d
EOSQL
              , (int)$product['id'], (int)$value['value_id']))->fetch_assoc();

            if ($virtual_check['total'] > 0) {
              // if any attribute is downloadable, the product is virtual
              // and doesn't count; so skip to the next product
              // without adding the line total
              continue 2;
            }
          }

          $physical_order_total += $currencies->calculate_price($product['final_price'], $product['tax'], $product['qty']);
        }
      }
 
if (($physical_order_total) > $this->base_constant('ORDERSOVER')) {	  
      return $this->quotes;
}

    }

    protected function get_parameters() {

      return [
        $this->config_key_base . 'STATUS' => [
          'title' => 'Enable Flat Shipping',
          'value' => 'True',
          'desc' => 'Do you want to offer flat rate shipping?',
          'set_func' => "Config::select_one(['True', 'False'], ",
        ],
        $this->config_key_base . 'ORDERSOVER' => [
          'title' => 'Orders over ',
          'value' => '0',
          'desc' => 'Use flat rate for order totals over this amount.',
        ],
        $this->config_key_base . 'COST' => [
          'title' => 'Shipping Cost',
          'value' => '5.00',
          'desc' => 'The shipping cost for all orders using this shipping method.',
        ],
        $this->config_key_base . 'TAX_CLASS' => [
          'title' => 'Tax Class',
          'value' => '0',
          'desc' => 'Use the following tax class on the shipping fee.',
          'use_func' => 'Tax::get_class_title',
          'set_func' => 'Config::select_tax_class(',
        ],
        $this->config_key_base . 'ZONE' => [
          'title' => 'Shipping Zone',
          'value' => '0',
          'desc' => 'If a zone is selected, only enable this shipping method for that zone.',
          'use_func' => 'geo_zone::fetch_name',
          'set_func' => 'Config::select_geo_zone(',
        ],
        $this->config_key_base . 'SORT_ORDER' => [
          'title' => 'Sort Order',
          'value' => '0',
          'desc' => 'Sort order of display.',
        ],
      ];
    }

  }

shop/includes/languages/english/modules/shipping:

Code: Select all

<?php
/*
  $Id$

 Release Date: 22/09/2024
 GetSirius

  Released under the GNU General Public License
*/

const MODULE_SHIPPING_SIRIUSFLAT_TEXT_TITLE = '<strong>Order total qualifies for Flat Rate Shipping</strong>';
const MODULE_SHIPPING_SIRIUSFLAT_TEXT_WAY = 'Our choice, generally least expensive.';

?>


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply