Woocommerce : Updating the user datas when a purchase is done seems not working
-
Hi everybody.
I’m trying to add a new role to a user who buys a product (=annual fee).
But my php code doesn’t work. It seems that the function I created is not used at all.
What is wrong in the following code that I add in the function.php file of the child theme ?
/** Add a new user type : adherent
* with limited possibilities
* the purpose is only to keep the info that the current user has paid the annual fee
*/
$result = add_role( ‘adherent’, __(
‘Adherent’ ),
array(
‘read’ => true, // true allows this capability
‘edit_posts’ => false, // user can’t edit their own posts
‘edit_pages’ => false, // user can’t edit pages
‘edit_others_posts’ => false, // user can’t edit others posts not just their own
‘create_posts’ => false, // user can’t create new posts
‘manage_categories’ => false, // user can’t manage post categories
‘publish_posts’ => false, // user can’t publish, otherwise posts stays in draft mode
‘edit_themes’ => false, // false denies this capability. User can’t edit your theme
‘install_plugins’ => false, // User cant add new plugins
‘update_plugin’ => false, // User can’t update any plugins
‘update_core’ => false // user cant perform core updates
)
);/**
* When a user pays the annual fee, a new role is added : adherent
*/add_action( ‘woocommerce_thankyou’, ‘the_user_is_updated’ );
function the_user_is_updated( $order_id ) {
$order = wc_get_order($order_id);
// Only continue if have $order_id
if ( ! $order_id ) {
echo ‘no current order’;
return;
}
$user_id = $order->get_user_id();
$user_id->add_role(‘adherent’);
echo ‘user updated’;
}Thanks for your help
- The topic ‘Woocommerce : Updating the user datas when a purchase is done seems not working’ is closed to new replies.