skip to Main Content

Adding a Column to the Table of Rates

The Table Rate shipping method for WooCommerce comes with a condensed table of rates featuring just three columns of data. While these columns can handle the core shipping features, there may be cases where you need to enter custom data used for other third party plugins. This is where the extensive list of filters and action hooks come in handy. With a little PHP knowledge, you can use these filters to add a new column and any form field you need that will work seamlessly with the other columns.

The following tutorial only works with Table Rate Shipping version 4.3 and newer.

Creating the New Column

Adding a new column is useful for adding meta data to the option that is not used as a condition or a cost value. For this example, let’s create a new select box in the table that stores which company is used to ship out the order. In this sample shop, smaller orders are shipped through USPS, but certain items require a different handler. Storing this information separately in the shipping option will help ease processing later and let the store’s management app know how to proceed.

Using the filter name betrs_shipping_table_columns we can add our new column and place it just before the ‘sorting’ column. The title of this column is Shipping Provider, and the unique ID is ‘provider’, which will be used for referencing this field later.

Populating the New Column

Now that the new column has been added, it’s time to add our settings field. We will be adding a select box already populated with the carriers our shop is using. The filter name for this step is betrs_shipping_table_column_{column-ID}, requiring our unique column ID. This ensures that the form field appears in the correct column. This is especially useful if you are adding multiple columns.

Staying with the same format as the other fields in the form, we have a multidimensional array for this field. The name of the select box has three parts: the custom field’s name, the option’s ID, and the row ID. This is the information used to determine which option and row the selection will be save to.

Saving the Selection

The last step is to save the admin’s selection at the same time the rest of the form is saved. In fact, it also saves the data directly to the table’s save data so everything is conveniently in one place.

With a new functional column in the table, the settings page portion is now complete!

BETRS add column

Saving the Custom Data

Just like the Description field in the table, these are added pieces of information not part of the WooCommerce core. Because of this, they are not automatically saved when an order is processed. If this information needs to be accessed later after the order is placed, it is a good idea to save it to the shipping option’s meta data.

This part works in the background while shipping is being calculated. If an option with a provider is selected as the final shipping option, it will save the meta data for review in the dashboard.

Display Data for Customers

We’ve already done the hard work of adding the content as meta data to the shipping option. Now that it is saved as shipping meta for the option, it is accessible from the cart and checkout pages, too.So if you are looking to also inform the customer of this extra information, one more small code snippet will add the content for display in the order summary.

With the option retrieved and added to the calculated shipping results, we can now display the data below the option.

  • Was this article helpful ?
  • yesno
0 out of 0 visitors found this article helpful
Views: 269
Back To Top