Last active
August 21, 2019 00:06
-
-
Save zgordon/adecb8351f20c68a55c2ee55dbc3db22 to your computer and use it in GitHub Desktop.
Assign users to a LearnDash Group when they purchase a specific WooCommerce product
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
<?php | |
// Add user to LearnDash Group if purchases specific WooCommerce product | |
function jsforwp_add_user_to_group( $order_id ) { | |
// Add group ID from LearnDash here | |
$ld_group_id = XXXX; | |
// Add product ID from WooCommerce here | |
$wc_product_id = XXXX; | |
$order = new WC_Order( $order_id ); | |
$items = $order->get_items(); | |
foreach ( $items as $item ) { | |
if ( $wc_product_id == $item['product_id'] ) { | |
ld_update_group_access( $order->customer_id, $ld_group_id, false ); | |
} | |
} | |
} | |
add_action( 'woocommerce_order_status_completed', 'jsforwp_add_user_to_group', 10, 1 ); | |
?> |
Oh - nevermind - found it in your post here:
https://wp.zacgordon.com/2017/05/10/add-user-to-learndash-group-when-orders-a-woocommerce-product/
:-) Thanks so much for creating this!
Cheers,
Rob
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
excatly what I was looking for - but now how do I use this file? :-) Thanks for clarifying!