#Overview
This filter is run when a WooCommerce Subscription’s data is synced to your CRM by WP Fusion:
- At checkout
- When a subscription status changes
- During a subscription renewal
- During a WooCommerce Subscriptions meta batch operation
It can be used to modify the subscription data that’s synced to your CRM.
To use the code examples below, add them to your active theme’s functions.php file.
#Parameters
$update_data
(array): The data to sync to your CRM.$subscription
(WC_Subscription): The subscription object.
#Examples
#Don’t sync the subscription start date during renewal payments
/**
* Filter the subscription data before syncing to CRM to exclude the start date on renewals.
*
* @param array $update_data The data to be sent to the CRM.
* @param WC_Subscription $subscription The subscription object.
* @return array Modified data array.
*/
function my_custom_wpf_subscription_sync_filter( $update_data, $subscription ) {
// Check if the order is a renewal order.
if ( wcs_order_contains_renewal( $subscription->get_last_order() ) ) {
// Remove the subscription start date for renewals.
unset( $update_data['sub_start_date'] );
// Also remove the start date for each product in the subscription.
foreach ( $subscription->get_items() as $line_item ) {
$product_id = $line_item->get_product_id();
unset( $update_data[ 'sub_start_date_' . $product_id ] );
}
}
return $update_data;
}
add_filter( 'wpf_woocommerce_subscription_sync_fields', 'my_custom_wpf_subscription_sync_filter', 10, 2 );
Was this helpful?
Let us know if you liked the post. That’s the only way we can improve.