I am trying to change the user role in wordpress after user buys one of 3 items. Each Iteam is like a membership, the only user that can't never be changed is the Admin. I have an Idea of the function I need but it is not working somehow. This should be a very very very easy job for a full time programmer. Being that this is an extremelly easy job I will not pay a lot of money for a 15 minutes job, so proce accordingly please.
add_action( 'woocommerce_order_status_completed', 'change_role_on_purchase' );
function change_role_on_purchase( $order_id ) {
$order = wc_get_order( $order_id );
$items = $order->get_items();
$user_meta=get_userdata($user_id);
$user_roles=$user_meta->roles;
$products_to_check = array( 349, 162, 317 );
foreach ( $items as $item ) {
if ( $order->user_id > 0 && in_array( 349, $products_to_check ) ) {
$user = new WP_User( $order->user_id );
// Change role
$user->remove_role($user_roles);
$user->add_role( 'Free Plan' );
}
if ( $order->user_id > 0 && in_array( 162, $products_to_check ) ) {
$user = new WP_User( $order->user_id );
// Change role
$user->remove_role($user_roles);
$user->add_role( 'Standard Plan' );
}
if ( $order->user_id > 0 && in_array( 317, $products_to_check ) ) {
$user = new WP_User( $order->user_id );
// Change role
$user->remove_role($user_roles);
$user->add_role( 'Premium Plan' );
// Exit the loop
}
}
}
Hi there!
Did go through your Job Description and glad to share that I have experience in working with wordpress platform. I have more than four years of industry experience and have been the part of diverse industry verticals.
I also have expertise with Magento,WordPress, PHP, PHP Scripting and CodeIgnitor along with Photoshop. So can help you with the design as well.
Looking forward to your response.
IT PROFESSIONAL AND COMPUTER ENGINEERING
Proficient in : Web development Graphic Designing Auto CAD CAM Data Entry App Development Black Linix Assignments of mathematics Assignments of physics Assignments of Chemistry Project Safety