Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to find the products associated with a WooCommerce subscription
/**
* How to get the product associated with a WooCommerce subscription
*/
function ct_checkout_subscription_created( $subscription, $order, $recurring_cart ) {
$id = $subscription->get_id(); // You can use this to set meta in the subscription
// Get the products in the order
$items = $order->get_items();
foreach( $items as $item ) {
$product = $item->get_product();
$product_id = $product->get_id();
// ... Do your stuff here
}
}
// Use any hook that passes the $subscription object
add_action( 'woocommerce_checkout_subscription_created', 'ct_checkout_subscription_created', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment