Hooks and functions reference

Linked Orders for WooCommerce provides a unified framework for linking follow-up orders to an existing root order. Its functionality can easily be extended using a few key hooks and functions.

Functions

All functions are located in the functions.php and src/functions files. You can check their parameters and return values in said locations. The components IDs can be found in the config_prod.php and config-premium_prod.php files.

Function nameDescription
dws_lowc_di_containerReturns the dependency injection container instance.
dws_lowc_instanceReturns the plugin’s main class instance from the DI container.
dws_lowc_componentReturns a given plugin component from the DI container by its ID.
dws_lowc_get_raw_settingReturns the raw database value of a given setting.
dws_lowc_get_validated_settingReturns the validated database value of a given setting.
Function nameDescription
dws_lowc_get_supported_order_typesReturns the order types that support linking. By default, that’s just shop_order but any object modelled by WC_Order can be used.
dws_lowc_get_valid_statuses_for_new_childFiltering the return value of this function will restrict the creation of child orders only to orders that have certain statuses.
dws_lowc_create_linked_orderCreates a new empty order linked to a given parent order.
dws_lowc_link_ordersLinks two orders in a parent-child relation.
dws_lowc_get_root_orderGoes up a linking tree and retrieves the root order for a given one.
dws_lowc_get_orders_treeReturns the full list of orders linked to the given one as the root.

Hooks

All hook tags are computationally generated to ensure uniqueness. It is possible to reverse-engineer the end-result, but it is recommended to just use the same helpers in order to ensure future-compatibility.

There are 2 helper functions to help you generate our hooks:

Function nameDescription
dws_lowc_get_hook_tagReturns a plugin-level hook.
dws_lowc_get_component_hook_tagReturns a component-level hook.

It’s recommended to use the action dws_lowc_initialized to register your hooks. It’s guaranteed that the functions above will be present and work on this action.

Filter valid order statuses for creating new child orders

add_action( 'dws_lowc_initialized', function() {
    add_filter(
        dws_lowc_get_component_hook_tag( 'post_type', array( 'valid_statuses_for_new_child' ) ),
        function( array $statuses, string $order_type, ?WC_Order $order ): array {
            return $statuses;
        },
        10,
        3
    );
} );Code language: PHP (php)

Modify linked orders before they’re saved

add_action( 'dws_lowc_initialized', function() {
    add_action(
        dws_lowc_get_component_hook_tag( 'created_linked_order' ),
        function( WC_Order $linked_order, WC_Order $parent_order ): void{
            // manipulate linked order here
        },
        10,
        2
    );
} );Code language: PHP (php)
Was this article helpful?

Need Support?

Can't find the answer you're looking for?
Contact Support

Need Support?

Can't find the answer you're looking for? Customers with an active license can log in into their account and post their questions on our support forum!
CONTACT SUPPORT