Created
April 8, 2023 05:52
-
-
Save KaineLabs/9be2fca8c52dfabedab3d5ac2ba88773 to your computer and use it in GitHub Desktop.
Youzify - BuddyPress Automatically add new users to a group after a complete payment in Woocommerce
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 | |
/* | |
* Youzify - BuddyPress Automatically add new users to a group after a complete payment | |
*/ | |
add_action( 'woocommerce_payment_complete', 'yzc_auto_join_groups_on_payment' ); | |
function yzc_auto_join_groups_on_payment( $order_id ) { | |
// Get data. | |
$order = wc_get_order( $order_id ); | |
$products = $order->get_items(); | |
$data = array( 'product_id1' => 'group_id1' , 'product_id2' => 'group_id2' ); | |
foreach ( $products as $prod ){ | |
if ( isset( $data[ $prod['product_id'] ] ) ) { | |
groups_accept_invite( $order->get_customer_id(), $data[ $prod['product_id'] ] ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment