Thank you for all people that help me to find an answer (0 helpers)!
I found a solution on my own.
function wpa_120656_convert_paying_customer( $order_id ) {
$order = new WC_Order( $order_id );
$user_id = $order->user_id;
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $user_id,
'post_type' => 'shop_order',
) );
if ( $customer_orders > 1 ) {
update_user_meta( $order->user_id, 'paying_customer', 1 );
$user = new WP_User( $order->user_id );
// Remove role
$user->remove_role( 'customer' );
// Add role
$user->add_role( 'dovclient' );
}
}
add_action( 'woocommerce_order_status_completed', 'wpa_120656_convert_paying_customer' );
Related Posts:
- WooCommerce: change display order of product short description and price [closed]
- How to remove action hook done in a plugin from functions.php in my theme?
- WooCommerce New customer email Hook? [closed]
- Add my own function to existing WooCommerce hook
- WooCommerce – Overwrite action hook [closed]
- Can I remove WooCommerce main content hook?
- Using hooks with extra parameters
- WooCommerce single product page quantity description [closed]
- Execute JavaScript in WordPress Hook
- Woocommerce table is missing a heading–can I add it by use of a hook?
- Hook triggered twice in a Woocommerce single product page
- Is there a way to send HTML formatted emails with WordPress’ wp_mail() function?
- Hook after image is uploaded and image sizes generated
- How to call a REST endpoint when a post is published?
- __NAMESPACE__ with register_activation_hook
- Hook for URL Request
- Hook/notify when any option or setting is added or updated
- Which hooks is this? add_action(‘wp’,
- admin_notices after register_uninstall / deactivate_hook
- add_action on inherit post status
- Why does wp_enqueue_script ignore my ‘wp_head’ hook?
- action lifecycle
- Redirect users on specific post category or category page
- Returning ACF custom field from publish_post
- How to modify an add_action() inside a loop of core function
- Replace existing content from specific WooCommerce admin orders list column
- How can I show an empty WooCommerce cart? [closed]
- Which has more impact on site performance? Template overrides or hooks
- What is the best filter where to use register_block_type?
- How get list all users who edited post?
- Increment price for Woocommerce Minicart [closed]
- Stuck in redirect loop after using wp_login action
- Hooks for Links Box [duplicate]
- Check if do_action(‘custom_action’) is hooked into?
- Hook after wp_enqueue_scripts
- wp_login Action hook with conditional tag
- How to update WordPress core or themes and still have my child theme hooks work
- Proper indentation of code generated inside hooks
- Add parameter (time) to oembed
- Remove Order List Row Link in WooCommerce Admin?
- how to add custom functionality after woocommerce place order button
- How can I count post views of REST API calls and update them in an ACF field?
- Event-Driven Pattern vs MVC?
- How to catch and modify custom field values when a page is updated
- Genesis: How to add content after aside and before the content-sidebar wrap
- new_to_publish fires multiple times
- Plugin init hook
- Best action hook for placing ical requests
- Is there a hook that fires when a row of wp_sitemeta table is updated?
- How to update custom field in WooCommerce
- `rest_user_query` can’t access post author in post edit screen
- Post Meta Emtpy on Publish Using Transition
- How to list all WC products by their attributes values?
- Showing the WordPress standard text area on a Woocommerce Single Product Page?
- How to check post type when using sanitize_title hook?
- How do I trigger a post update within a get_posts() foreach loop?
- Filtering WooCommerce Orders by Category
- Duplicate Cron Jobs Using wp_next_scheduled / wp_schedule_event
- How to change the default mail when admin approuved an user?
- How to modify how the_content outputs a link to an internal page
- read more, even if excerpt not trimmed
- How do I prevent term from being created on create_term hook?
- How to distinguish on hook profile_update user registering, user resetting password or user updating profile?
- Hook function prints output twice
- Hook priority in admin with custom plugin
- Embeding style into the header via the function.php
- ‘save_post’ hook not working in WP 3.5
- Change the Default Plugin page filter to Active intead of All
- WooCommerce: after install hook
- How to execute a hook asynchronously?
- Issues with if, else, and elseif statements
- Woocommerce – Adding row to cart table
- Is there a before_save_post hook or something similar
- “Seen by” Feature in posts [closed]
- How to hook in to the “output buffer” and add html content
- hook for loading page
- What hook to use to redirect based on $post
- How can I modify the header of RSS feed items?
- Print results of a WP_Query to wp-admin/upload.php within ‘delete_attachment’ hook?
- upgrader_process_complete filter not fired using ajax updates
- How to debug wordpress hooked functions?
- How to sort WooCommerce products page by latest in-stock items first?
- remove_action(‘save_post’) in function that was triggered by save post not working
- How to get template name or category before publish
- WordPress How to reorder Page/Post Settings
- Is there a way to Insert a post to post list?
- “Intercept” enqueing of 3rd party’s JS file
- WP hook to add custom content after the_title()
- add a hook of Woocommerce to a plugin but it only shows and doesn’t function properly
- ACF Fields are not showing up on Homepage
- wp_get_current_user Not working
- How to delete WooCommerce categories in bulk that only have one product
- Hook woocommerce price in backend order edition
- Display custom debug info inside page and not before head
- How WordPress understands what do with the (all) key in the $wp_filter array? [duplicate]
- WP-Automatic to run publish hooks
- Why does hook priority affects admin menu permission error?
- Send a custom notification to customer on WooCommerce cancelled order status
- How can I get the ID before after_setup_theme?
- Hook on opening a media/document