skip to Main Content

Add a New Settings Field

The Table Rate Shipping plugin for WooCommerce has many features for customizing your shipping, and even more available through extensions. However, there may be times where it’s helpful to add your own selection box at the method level. This is where the extensive list of filters and action hooks come in handy. With a little PHP knowledge, you can add a new field to any section and apply its changes dynamically.

Adding the New Settings Field

In this example, we will be focusing on the Additional Options section. An admin needs the ability to select a variety of delivery codes for each shipping method. These selections will be stored as meta data with the shipping option for later access. To make this easier to setup, a multi-select box is used prepopulated with the available options.

Using the woocommerce_shipping_instance_form_fields_betrs_shipping filter we can modify the settings fields on the Table Rate page. In this case, we are modifying the “other” section, which is the “Additional Options” section. A new field with the ID shipping_carriers is added with the available selections. The best part? We’re done! Because this is a pre-existing system that we are simply adding into, the new field will be able to save and retrieve the selection without any additional code.

Using the New Field

So we have a new field that is working and that’s great! But what’s next? How you use this new field is up to you and will depend on it’s primary purpose. If you are altering a calculated value, you will need another filter in order to do so. If you need another third party plugin to retrieve this value during calculation, you will need to use the hooks or filters supplied by them. So long as you have direct access to the shipping method, getting the selection is not difficult.

$carriers = $shipping_method->get_option( 'shipping_carriers' );
  • Was this article helpful ?
  • yesno
0 out of 0 visitors found this article helpful
Views: 258
Back To Top