Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Created April 8, 2023 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/9be2fca8c52dfabedab3d5ac2ba88773 to your computer and use it in GitHub Desktop.
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
<?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