Name
woo_sl/order_processed/product_sl
Type
Filter
Arguments
(array) $data
(object) $order_item
(int) $order_id
Description
The woo_sl/order_processed/product_sl filter allows developers to modify the license-related data associated with a product in a WooCommerce order before it is saved into the order item metadata.
This hook is useful for customizing licensing behavior dynamically, such as changing the number of allowed keys, modifying expiration times, or adding additional flags based on order context or custom logic.
Here’s a standalone example showing how you can hook into woo_sl/order_processed/product_sl to tweak the license data before it’s saved. In this case we’ll:
- Prefix every license key with a custom string.
- Double the expiration time for products in a specific category.
- Add a custom flag into the data array.
/**
* Customize license data before saving to order item meta.
*
* @param array $data Original license data arrays.
* @param WC_Order_Item_Product $order_item The order item object.
* @param int $order_id The ID of the processed order.
* @return array Modified license data.
*/
function my_custom_modify_license_data( $data, $order_item, $order_id ) {
// 1) Add a custom prefix to every licence_prefix entry
foreach ( $data['licence_prefix'] as $i => $prefix ) {
$data['licence_prefix'][ $i ] = 'MYCOMPANY-' . $prefix;
}
// 2) If product is in 'extended-support' category, double its expire time
$product = $order_item->get_product();
if ( $product && has_term( 'extended-support', 'product_cat', $product->get_id() ) ) {
foreach ( $data['product_expire_time'] as $i => $secs ) {
$data['product_expire_time'][ $i ] = intval( $secs ) * 2;
}
}
// 3) Add a custom flag for downstream processing
$data['my_custom_flag'] = array_fill( 0, count( $data['group_title'] ), true );
return $data;
}
add_filter( 'woo_sl/order_processed/product_sl', 'my_custom_modify_license_data', 10, 3 );
Read more