Automation: automatically create stamps for WooCommerce orders


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

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

  • Create at most one stamp per order for the first rule that applies: In this case, at most one stamp per WooCommerce order is automatically created, namely for the first rule that applies. Stamps that were previously created manually (via editor or bulk order) are not counted.
  • Create at most one stamp per WooCommerce order status: This option can be used to automatically create multiple stamps per WooCommerce order. At most one stamp is created per WooCommerce status. For example, rules can be defined so that different stamps are automatically created for the status “Processing” and for the status “Refunded”.
  • Create stamps for all rules that apply but only once per order: As soon as a rule applies, stamps are created for all rules that apply. After that, stamps will no longer be created automatically for the order.
  • Create stamps for all rules that apply (once per order status): This option is similar to “Create at most one stamp per WooCommmerce order status”, but for each order status all rules are checked and potentially multiple stamps 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 “WebStamp > Templates”). If an order meets all the rules, one or more stamps 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 stamp 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 stamp 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 stamps can then be automatically attached to admin emails (see Attaching stamps 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 stamps. Depending on the template logic, different stamps are created:

  • Create at most one stamp per order for the first rule that applies: When the order reaches the status “Processing”, a stamp is created for the “Standard 100g” template or for the “Midi” template, depending on whether the total weight of the items in the order is lower or higher than 100g. After that no stamp will be created automatically.
  • Create at most one stamp per WooCommmerce order status: Potentially two stamps will be created.
    • If the order status is “Processing”, a stamp is created for one of the templates “Standard 100g” or “Midi” depending on the total weight of the order.
    • If the order is refunded, a stamp for the “Midi 50mm” template is created, regardless of whether a stamp for the order status “Processing” was previously created.
  • Create stamps for all rules that apply but only once per order: When order status “Processing” is reached, potentially two stamps are created. After that, no more stamps will be created for the order (not even if the order status is different).
    • A stamp is created for template “Standard 100g” or “Midi”.
    • 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 20 cm³ (both rules must apply), an additional stamp for the “Grossbrief” template is created.
  • Create stamps for all rules that apply (once per order status): Up to 3 stamps are created here:
    • First, a stamp for template “Standard 100g” or “Midi” 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 20 cm³ (both rules must apply), an additional stamp for the “Priority” template is created.
    • If the order is refunded, a stamp for the “Midi 50mm” template is created, regardless of whether a stamp for the order status “Processing” was previously created.