-
Disable Specific States in Ubercart
Here’s a quick example that illustrates how to remove a few State/Province options from the billing and shipping panes of the Ubercart checkout form, as well as the order edit/create form. Please understand there are other ways to do this (like altering the united_states_840_1.cif file and re-importing). The hook_form_alter() method seems less permanent, so I favor it.
123456789101112131415161718192021/*** Implementation of hook_form_alter().*/function mymodule_form_alter(&$form, &$form_state, $form_id) {switch ($form_id) {case 'uc_cart_checkout_form':// Disable some State/Province values in the checkout formunset($form['panes']['delivery']['delivery_zone']['#options'][21]); // Hawaiiunset($form['panes']['delivery']['delivery_zone']['#options'][49]); // Oregonunset($form['panes']['billing']['billing_zone']['#options'][21]); // Hawaiiunset($form['panes']['billing']['billing_zone']['#options'][49]); // Oregonbreak;case 'uc_order_edit_form':// Disable some State/Province values in the order edit/create formunset($form['ship_to']['delivery_zone']['#options'][21]); // Hawaiiunset($form['ship_to']['delivery_zone']['#options'][49]); // Oregonunset($form['bill_to']['billing_zone']['#options'][21]); // Hawaiiunset($form['bill_to']['billing_zone']['#options'][49]); // Oregonbreak;}} -
Get the Value of the Cheapest Option for an Ubercart Product
This is just a quick code example. Imaging you have an Ubercart attribute that has several options and you’d like to show an “As low as $X.XX” price on the frontend. Here’s a simple solution. Note that if you wanted the lowest price across ALL attributes you could loop through each attribute too (instead of just looking at attributes[1]).
123456789if ($node->attributes[1]->options) {// Get lowest price of all "Units" attribute options$prices = array();foreach ($node->attributes[1]->options as $opt) {$prices[] = $opt->price;}$output .= t('As low as !price', array('!price' => uc_currency_format(min($prices))));} -
Adding a Custom Token to the Ubercart (before version 2.3) Email Templates
This tutorial is for Ubercart versions earlier than version 2.3. There is a newer version of this example for Ubercart 2.3 or later.
In this post I’ll show how to set up an extra token for use in an Ubercart template. This will require creating a custom module (because we don’t really want to modify others’ modules). We’ll use a few different hooks to create the token, and then simply modify the template to include this token. This setup requires the token module (which is required by Ubercart), so make sure this is enabled!
-
Adding a Custom Token to the Ubercart (version 2.3 or newer) Email Templates
This tutorial is for Ubercart versions later than version 2.3. If you’re using an older version of Ubercart, you’ll want to see this example. This example is very similar, but accommodates the changes made to the template system in Ubercart.
In this post I’ll show how to set up an extra token for use in an Ubercart template. This will require creating a custom module (because we don’t really want to modify others’ modules). We’ll use a few different hooks to create the token, and then modify the template (or create a new template) to include this token. This setup requires the token module (which is required by Ubercart), so make sure this is enabled!