Get Notified When a User Removes an Item from a WooCommerce Subscription

1 Comment

  1. Rumano

    As an alternative programmatic solution, you can add this function to the functions.php file, which is located in your current theme folder.

    /*
    * Update Subscription when subscription line item has been removed or restored.
    */
    function trigger_wcs_webhook_updated() : void
    {
    if(
    is_user_logged_in()
    && isset($_GET[‘subscription_id’]) && is_numeric($_GET[‘subscription_id’]) && $_GET[‘subscription_id’] >= 1
    &&
    (
    isset($_GET[‘remove_item’]) && is_numeric($_GET[‘remove_item’]) && $_GET[‘remove_item’] >= 1
    || isset($_GET[‘undo_remove_item’]) && is_numeric($_GET[‘undo_remove_item’]) && $_GET[‘undo_remove_item’] >= 1
    )
    && isset($_GET[‘_wpnonce’])
    && wp_verify_nonce( $_GET[‘_wpnonce’], $_GET[‘subscription_id’] )
    && wcs_is_subscription( $_GET[‘subscription_id’] )
    )
    {
    $oSubscription = wcs_get_subscription($_GET[‘subscription_id’]);

    WCS_Webhooks::add_subscription_updated_callback($oSubscription);
    }

    }
    add_action(‘wcs_user_readded_item’, ‘trigger_wcs_webhook_updated’, 11 );
    add_action(‘wcs_user_removed_item’, ‘trigger_wcs_webhook_updated’, 11 );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.