Created
November 5, 2018 09:59
-
-
Save plugin-republic/5e01f97428073fe72dd6ae1ca73b490a to your computer and use it in GitHub Desktop.
How to find the products associated with a WooCommerce subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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