• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

WooCommerce Subscriptions: Remove role on cancelled subscription

phpwordpresswoocommercehook-woocommercewoocommerce-subscriptions


PHP Snippet 1:

add_action('woocommerce_subscription_status_cancelled', 'wcs_maybe_remove_role', 10, 1);

function wcs_maybe_remove_role($subscription) {
    $user_id = $subscription->get_user_id();
    $user = new WP_User($user_id);
    $user->remove_role('silver');
    $user->remove_role('gold');
}

Related Snippets

How do I pass the dynamic output of a php variable or php function to a CSS variable?

Move a child array to parent array and change parent/child name

PHP: Telegram Bot: Insert line break to text message

Nginx disallowing execution of PHP in uploads directory with Magento

Twig - How to check if variable is a number / integer

Load a .env file with PHP

Show Custom Data in Woocommerce Order Details Admin Area

Change user role if checkout custom checkbox is checked in WooCommerce

How to modify CSS in a specific page of the WP admin dashboard (backend)

How to set time with DateTime modify?

PHP password_verify

Google Gmail API - How to login programatically?

PHP Warning: Module already loaded in Unknown on line 0

Custom Button next to “ADD TO CART” button of WooCommerce based on Product Type

Invalid value in field "itemtype" in Google Search Console

About Contact Privacy policy Terms and conditions