Automation: automatically create labels for WooCommerce orders


Labels can be created automatically when a WooCommerce order is placed by defining rules under “Barcode > Settings > Automation”.

In the field “Template rules logic” you can define whether one or potentially multiple labels are created per WooCommerce order if the rules under “Template rules” apply. The following settings are possible:

  • Create at most one label per order for the first rule that applies: In this case, at most one label per WooCommerce order is automatically created, namely for the first rule that applies. Labels that were previously created manually (via editor or bulk order) are not counted.
  • Create at most one label per WooCommerce order status: This option can be used to automatically create multiple labels per WooCommerce order. At most one label is created per WooCommerce status. For example, rules can be defined so that different labels are automatically created for the status “Processing” and for the status “Refunded” (e.g. for GAS labels).
  • Create labels for all rules that apply but only once per order: As soon as a rule applies, labels are created for all rules that apply. After that, labels will no longer be created automatically for the order.
  • Create labels for all rules that apply (once per order status): This option is similar to “Create at most one label per WooCommmerce order status”, but for each order status all rules are checked and potentially multiple labels are created (instead of just one per order status).

In the “Template rules” field, corresponding rules for already created templates can be added (templates can be created under “Barcode > Templates”). If an order meets all the rules, one or more labels will be automatically created for the order (depending on the template logic above) when the order reaches a defined status. The following points must be observed:

  • Rules within a rule box are considered AND rules, i.e. all rules must be fulfilled for the label to be generated.
  • Multiple rule groups for the same template are considered OR rules, i.e. all rules within at least one rule group must match for a label to be generated.
  • The rules are processed from top to bottom, i.e. rules higher up have higher priority. Rule groups can be rearranged using drag-and-drop.
  • The BETWEEN rule is inclusive (i.e. the entered values ​​are included in it).
  • The volume is the sum of all volumes of the products included in the order multiplied by their number. It may therefore be that the products cannot be arranged in such a way that they fit into the package, even though their total volume is smaller than the maximum volume defined in the rule.
  • If a rule box is added but no rule is specified (weight, volume, etc.), the rule always applies (for the selected order status).
  • The created labels can then be automatically attached to admin emails (see Attaching labels to emails).

 

Custom rule (programming skills required)

With the rule “Custom rule (filter)” you can use your own code to determine whether a rule should apply to a WooCommerce order or not by using the filter name next to the rule:

add_filter('mame_bc_ws_filter_1645709108954', 'mame_test_bc_ws_filter', 10, 2);

function mame_test_bc_ws_filter($passed, $wc_order){

    // Do something.

    return $passed;
}

The filter function expects two arguments:

  • bool $passed: the value to filter (default: true).
  • WC_Order $wc_order: The WooCommerce order object.

The return value must either be true or false depending on whether the rule applies or not.

 

 

Example

The screenshot below shows an example of defined rules for automatic creation of labels. Depending on the template logic, different labels are created:

  • Create at most one label per order for the first rule that applies: When the order reaches the status “Processing”, a label is created for the “ECO 5 kg” template or for the “ECO 10 kg” template, depending on whether the total weight the item in the order is lower or higher than 5kg. After that no label will be created automatically.
  • Create at most one label per WooCommmerce order status: Potentially two labels will be created.
    • If the order status is “Processing”, a label is created for one of the templates “ECO 5 kg” or ECO 10 kg” depending on the total weight of the order.
    • If the order is canceled, a label for the “GAS” template is created, regardless of whether a label for the order status “Processing” was previously created.
  • Create labels for all rules that apply but only once per order: When order status “Processing” is reached, potentially two labels are created. After that, no more labels will be created for the order (not even if the order status is different).
    • A label is created for template “ECO 5 kg” or “ECO 10 kg”.
    • If the selected shipping method is “Free shipping (zone: CH)” and if the calculated required box size for the items is less than or equal to 100 cm³ (both rules must apply), an additional label for the “Priority” template is created.
  • Create labels for all rules that apply (once per order status): Up to 3 labels are created here:
    • First, a label for template “ECO 5 kg” or “ECO 10 kg” is created if the order status is “Processing”.
    • If the selected shipping method is “Free shipping (zone: CH)” and if the calculated required box size for the items is less than or equal to 100 cm³ (both rules must apply), an additional label for the “Priority” template is created.
    • If the order is canceled, a label for the “GAS” template is created, regardless of whether a label for the order status “Processing” was previously created.