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 name | Description |
---|---|
dws_lowc_di_container | Returns the dependency injection container instance. |
dws_lowc_instance | Returns the plugin’s main class instance from the DI container. |
dws_lowc_component | Returns a given plugin component from the DI container by its ID. |
dws_lowc_get_raw_setting | Returns the raw database value of a given setting. |
dws_lowc_get_validated_setting | Returns the validated database value of a given setting. |
Function name | Description |
---|---|
dws_lowc_get_supported_order_types | Returns 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_child | Filtering the return value of this function will restrict the creation of child orders only to orders that have certain statuses. |
dws_lowc_create_linked_order | Creates a new empty order linked to a given parent order. |
dws_lowc_link_orders | Links two orders in a parent-child relation. |
dws_lowc_get_root_order | Goes up a linking tree and retrieves the root order for a given one. |
dws_lowc_get_orders_tree | Returns 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 name | Description |
---|---|
dws_lowc_get_hook_tag | Returns a plugin-level hook. |
dws_lowc_get_component_hook_tag | Returns a component-level hook. |
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)