WooCommerce Change User Role on Purchase of Product with a certain keyword (tag)
-
Hello,
I found this code in this forum:function lgbk_add_member( $order_id ) { $order = new WC_Order( $order_id ); $items = $order->get_items(); foreach ( $items as $item ) { $product_name = $item['name']; $product_id = $item['product_id']; $product_variation_id = $item['variation_id']; if ( $order->user_id > 0 && $product_id == '33' ) { update_user_meta( $order->user_id, 'paying_customer', 1 ); $user = new WP_User( $order->user_id ); // Remove role $user->remove_role( 'subscriber' ); // Add role $user->add_role( 'contributor' ); } } } add_action( 'woocommerce_order_status_completed', 'lgbk_add_member' );
It is working great but as I have like 200 products in my shop, i guess it wouldn’t be good to copy this code for almost 50 products. So my question: Is there a way to achieve the same thing but not for a specific product but for more products like from a certain category or better with a specific keyword?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘WooCommerce Change User Role on Purchase of Product with a certain keyword (tag)’ is closed to new replies.