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

Skills: CSS, HTML, PHP, WooCommerce, WordPress

See more: 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

About the Employer:
( 2 reviews ) Paarl, South Africa

Project ID: #18925038

Awarded to:


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!

$25 USD in 1 day
(265 Reviews)

5 freelancers are bidding on average $33 for this job


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 More

$66 USD in 1 day
(992 Reviews)

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.

$30 USD in 1 day
(877 Reviews)

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 More

$30 USD in 2 days
(172 Reviews)

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 More

$15 USD in 1 day
(0 Reviews)