woocommerce change role based on items qty bought in last 12 months

hello there, I need coding that changes a user role in wordpress/woocommerce based on the quantity of a product a user buys within a year period....I have the code already based on the purchase of a specific product but I need it adapted to check the total quantity of a a users purchases in a year and if the purchase quantity goes over a specific amount of items in a year then the user role must change automatically

function change_role_on_purchase( $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 == '416' ) {

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( 'premium' );




add_action( 'woocommerce_order_status_processing', 'change_role_on_purchase' );

Compétences : CSS, HTML, PHP, WooCommerce, WordPress

en voir plus : change price based currency selected html php, drupal ubercart change role, flash game change text based score, woocommerce change product price based on quantity, wc role based price pro, woocommerce change product price programmatically, woocommerce custom price, woocommerce role based pricing, woocommerce multiple prices per product, woocommerce role based pricing pro nulled, woocommerce price display, php change content based url, zen cart pricing based items, change image based input, virtuemart change image based attribute selected, demo role based templates, role based diagram generator, change image based referer site, php change css based users referral, role based authentication using sql server 2005 aspnet

Concernant l'employeur :
( 2 commentaires ) Paarl, South Africa

Nº du projet : #18925038

Décerné à:


Hello I will make the user's role changed based on the item quantity they have purchased in the last year. Let me know more details in chat. Thanks!

%selectedBids___i_sum_sub_4% %project_currencyDetails_sign_sub_5% USD en 1 jour
(265 Commentaires)

5 freelance font une offre moyenne de $33 pour ce travail


Hi there, Quick and easy. Do you need to just match the Product quantity from ALL ordered products within the year? OR do you want to include / exclude certain products / variations? I'll need WP admin and cPanel Plus

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(992 Commentaires)

Hello, I think I understand it. We will retrieve orders for last 1 year and count products in order. If it's more than xx, user role will be changed.

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(877 Commentaires)

Sir, I can give this work with 100% satisfaction within a time limit, and also I have great hands-on HTML, CSS, JS, jQuery, PHP, Laravel, MySQL. Very familiar with WordPress, Magneto, woo-commerce, Bootstrap, Plugi Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 2 jours
(172 Commentaires)

Hello,how do you do? I am a full stack developer for WooCommerce and Wordpress. I have read your description in more detail and have much interest in your project. I have many experiences what I have ever done before s Plus

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(0 Commentaires)