Extra options code samples

Introduction

WooCommerce DYMO Print has a couple of hidden features which you can use by adding filters to your theme’s functions.php or a custom plugin. More information about filters for WordPress.

With the filters on this page you can modify the behavior of WooCommerce DYMO Print in several ways. Filters are for advanced users only. Do not ask us to write or adjust these codes for you.

If you do not know how filters work, do not use them!

Back-up first! If you do something wrong, adding code to your functions.php can break your site!

Code: Add new label

As from WooCommerce DYMO Print version 3.0 you can add as many labels as you need. By default we add Shipping labels and Billing labels.

Example use

  1. Add two types of shipping labelsLarge package and Small package
  2. Add extra label for warehouse managementWarehouse label
  3. Add labels for each shipping methodUPS label, DHL label and pick-up label

Basic example to add label

Add the following code to your theme functions.php or a custom plugin to add a new label.

What do you need to change in the code?

The key of the label. In the example: new-label (line 2).
The key must be unique and may not contain any spaces, numbers or special characters.

The name of the label. In the example: New label (line 3).
The name is shown in the DYMO settings and on print buttons. Change it to whatever you want.

The color of the label icon. In the xample: #ff3300 (line 4).
The color makes you recognize the label a lot easier. Use any HTML color. Don’t forget the hashtag (#).

The type of the label. In the example: order (line 5).
Use “order” for order labels. Also allowed: order_item (for order item labels).

Do not alter the filter name “wpf_woocommerce_dymo_labels“, otherwise the filter becomes quite useless.

If you have installed our WooCommerce DYMO Print Product add-on the “wpf_woocommerce_dymo_labels” filter can also be used to add new product labels.

Code: Delete label

If you do not need our default labels you can delete them. The following code snippet deletes the default Billing label.

Add the following code to your theme functions.php or a custom plugin to delete a label.

Code: Modify label

If you want to modify our default labels you can use the same code. The following code snippet modifies the name and color of the default Shipping label.

Add the following code to your theme functions.php or a custom plugin to modify a label.

Code: Change number of labels per order

This filter can only be used for order and order item labels. This filter does not work for product labels.

By default 1 label is printed per order. However you can change how many labels to be printed per order.

Example use

  1. Print 2 labels for every order
  2. Print 4 labels for orders with specific shipping method
  3. Print 2 labels for shipping purposes, print 1 label for billing purposes
  4. Print 3 labels for order with more than 5 products
  5. Print a label for each product inside an order
  6. Print an extra label if the total product weight is above 10 kg

Basic example: print 2 labels for every order

To print 2 labels for every order place the following code in your theme’s functions.php or in a custom plugin.

Definition of variables

Do not alter the filter name “wpf_woocommerce_dymo_labels“, otherwise the filter becomes quite useless.

The filter uses the following variables:

  • $amount = the current amount, by default 1. The amount needs to be returned to the plugin. Needs to be an integer.
  • $order = the order object of the current order.
  • $label = the current label, for example ‘shipping’. This is the key of the label and is always unique.

Advanced example: print an extra label if the total product weight is 10 kg or more

The following example shows advanced use of the filter. We first check if the default Shipping label is printed. After that we get the total weight of all products inside the order. If the total product weight is 10kg or more, we print an extra label. If not, we print 1 label.

Code: Overwrite order item attribute output

As from WooCommerce DYMO Print version 3.1.1. it’s possible to overwrite the output of order-item attribute data. By default the order-item attribute data looks like: label: value.

Some people wanted to overwrite the output, so they can add another label or a suffix to the value.

To overwrite order item attribute data  you need to choose the option “Order item attributes (requires WC 3.1)” option from the configuration dropdown.

Select: Order Item attributes (requires WC 3.1)

You also need to use a filter to overwrite the output.

Back-up first! If you do something wrong, adding code to your functions.php can break your site!

Add the following filter to your theme functions.php or a custom plugin.

There are 3 variables in this filter:

  • $output = default output as used in the plugin. Example: ‘Weight (g): 2’
  • $value = value from attribute data. Example: ‘2’
  • $key = label from attribute data. Example: ‘Weight (g)’

To remove the label (key) and add a suffix to the output of attributes use the following example code:

If your products have multiple attributes the varible $key could be used to identify the $key and return a specific output for it.

Sample labels

If you’re looking for sample labels, you’re on the wrong page. Click here to download our sample labels.

Questions about filters?

The filters on this page are for advanced users only. We can not write custom code for you for free. However if you’ve a specific wish for code or functions we can do custom development for you. Contact us for a quote.