Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Add this to your custom functions.php or to
- * your custom plugin to update the Wordpress role
- * or the member type of the user in BuddyBoss plugin
- * after the user has purchased a product.
- */
- // Update Wordpress Role and Profile Type after purchase, WooCommerce
- function chrmrtns_change_role( $order_id ) {
- // get all the order data
- $order = new WC_Order($order_id);
- //get the user email from the order
- $user = $order->get_user();
- // if the this is a registered user and this user is not an admin
- if( false != $user && !user_can($user, 'administrator') ){
- // our new role name
- $role = 'customer';
- // our new profile type, you need to set a profile type first
- $profile = 'vip-mitglied';
- //set the new role to our customer
- $user->set_role($role);
- // Get the user ID
- $user_id = get_post_meta($order_id, '_customer_user', true);
- bp_set_member_type($user_id, $profile);
- }
- }
- //add this newly created function to the thank you page
- add_action( 'woocommerce_thankyou', 'chrmrtns_change_role', 100, 1 );
- // You can use other hooks and adjust your function accordingly.
- // See: https://woocommerce.com/document/subscriptions/develop/action-reference/
- // Triggered when a payment fails for a subscription. This can be for payment of the initial
- // order, a switch order or renewal order.
- // add_action( 'woocommerce_subscription_payment_failed', 'chrmrtns_change_role', 100, 1 );
- //
- // Unlike the 'woocommerce_subscription_payment_failed' hook, this hook is not triggered for failed payments on the
- // initial order or a switch order. It is only triggered for payments on renewal orders.
- // add_action( 'woocommerce_subscription_renewal_payment_failed', 'chrmrtns_change_role', 100, 1 );
- //
- // Description: Similar to WooCommerce’s 'woocommerce_order_status_changed' hook, this action is triggered
- // immediately after a subscription’s status has been changed.
- // It will be triggered for all status changes defined by WooCommerce Subscriptions, including: pending, active,
- // on-hold, pending-cancel, cancelled, or expired; as well as any custom subscription statuses.
- // add_action( 'woocommerce_subscription_status_updated', 'chrmrtns_change_role', 100, 1 );
- //
- //
- // add_action( 'woocommerce_order_status_changed', 'chrmrtns_change_role', 100, 1 );
- //
- //
- // add_action( 'woocommerce_subscription_status_active', 'chrmrtns_change_role', 100, 1 );
- //
- //
- // add_action( 'woocommerce_subscription_status_cancelled', 'chrmrtns_change_role', 100, 1 );
- //
- //
- // add_action( 'woocommerce_subscription_status_expired', 'chrmrtns_change_role', 100, 1 );
- //
- //
- // add_action( 'woocommerce_subscription_status_on-hold', 'chrmrtns_change_role', 100, 1 );
Advertisement
Add Comment
Please, Sign In to add comment