Skip to content

Instantly share code, notes, and snippets.

View thenbrent's full-sized avatar

Brent Shepherd thenbrent

View GitHub Profile
@thenbrent
thenbrent / wcs-remove-my-subscriptions-buttons.php
Last active October 19, 2023 06:22
Remove any given button from the My Subscriptions table on the My Account page. By default, only the "Change Payment Method" button is removed, but you can uncomment additional actions to remove those buttons also.
<?php
/**
* Plugin Name: Remove Subscription Action Buttons from My Account
* Plugin URI: https://gist.github.com/thenbrent/8851287/
* Description: Remove any given button from the <a href="http://docs.woothemes.com/document/subscriptions/customers-view/#section-2">My Subscriptions</a> table on the My Account page. By default, only the "Change Payment Method" button is removed, but you can uncomment additional actions to remove those buttons also.
* Author: Brent Shepherd
* Author URI:
* Version: 2.0
*/
@thenbrent
thenbrent / extend-subscription-intervals.php
Last active September 10, 2023 12:03
Add a new billing interval to WooCommerce Subscriptions. Specifically a "every 10 weeks" billing interval to selling a subscription to something and be charged every 10 weeks.
<?php
/**
* Plugin Name: Extend WooCommerce Subscription Intervals
* Description: Add a "every 10 weeks" billing interval to WooCommerce Subscriptions
* Author: Brent Shepherd
* Author URI: http://brent.io
* Version: 1.0
* License: GPL v2
*/
@thenbrent
thenbrent / subscription-renewal-process.md
Created August 8, 2016 17:52
Brief developer's guide to the application flow during the subscription renewal process within WooCommerce Subscriptions

WoCommerce Subscriptions processes automatic renewal payments via the following flow:

  1. its scheduling system, Action Scheduler, will run every minute and find any woocommerce_scheduled_subscription_payment actions scheduled to run now or within the last minute
  2. if there are woocommerce_scheduled_subscription_payment actions scheduled for anytime before now, Action Scheduler will grab a batch of those actions and begin processing them (which just means triggering do_action( 'scheduled_subscription_payment', $subscription_id ) for any 3rd party code to handle)
  3. Subscriptions attaches two important functions as callbacks on the 'woocommerce_scheduled_subscription_payment' hook to process renewal for that subscription when it is called:
  4. WC_Subscriptions_Manager::prepare_renewal(), which is responsible for
@thenbrent
thenbrent / no-renewal-emails-for-zero-reneawl.php
Last active August 26, 2023 07:35
Do not send renewal order emails when the email relates to a $0 renewal.
<?php
/*
Plugin Name: WooCommerce Subscriptions No $0 Emails
Plugin URI:
Description: Do not send processing or completed renewal order emails to customers when the order or renewal is for $0.00.
Author:
Author URI:
Version: 0.1
*/
@thenbrent
thenbrent / switch-subscription-link.php
Created November 13, 2013 19:27
Output a link to switch a subscription for the current user.
@thenbrent
thenbrent / example-paypal-ipn-payloads.txt
Last active February 8, 2023 07:04
PayPal Standard & Express Checkout Subscription Related IPN Messages (from Sandbox)
-------------------------------------
PayPal Standard Subscription Sign-up
-------------------------------------
[txn_type] => subscr_signup
[subscr_id] => I-NARPL1C0KAHA
[last_name] => User
[residence_country] => US
[mc_currency] => AUD
[item_name] => Digital Subscription
@thenbrent
thenbrent / wp_rewrite_rules.log
Created August 7, 2012 23:46
Default WordPress Rewrite Rules
[rules] => Array (
[category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/page/?([0-9]{1,})/?$] => index.php?category_name=$matches[1]&paged=$matches[2]
[category/(.+?)/?$] => index.php?category_name=$matches[1]
[tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/page/?([0-9]{1,})/?$] => index.php?tag=$matches[1]&paged=$matches[2]
[tag/([^/]+)/?$] => index.php?tag=$matches[1]
[type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?post_format=$matches[1]&feed=$matches[2]
@thenbrent
thenbrent / wc-queue-docs.md
Last active December 2, 2022 17:24
WooCommerce 3.5 introduced a new scalable, traceable job queue. This queue can be leveraged by extensions for processing large sets of jobs in the background. The default handler can also be replaced for custom requirements.

Job Queue API

WooCommerce 3.5 introduced a new scalable, traceable job queue. This queue can be used by extensions and custom code to process large sets of jobs in the background, and track the lifecycle of those jobs. The default handler can also be replaced.

This guide explains how to use the queue APIs for adding jobs, and how to replace the default queue handler.

Jobs are Actions

For flexibility and simplicity, each job is defined by an action hook.

@thenbrent
thenbrent / create-test-scheduled-actions.php
Last active December 2, 2022 17:24
Snippet to create scheduled actions with Action Scheduler via $_GET params.
<?php
/**
* Check for $_GET params on admin pages and use them to create corresponding actions.
*
* Example URL string to append to any admin page: &as_add_actions=single&hook=my_action&time=1563420973
*/
function as_test_schedule_async_action() {
if ( ! isset( $_GET['as_add_actions'] ) ) {
return;
}
@thenbrent
thenbrent / _subscriptions.md
Last active November 22, 2021 05:31 — forked from mattallan/_subscriptions.md
WooCommerce Subscriptions REST API Endpoint Documentation (fork of https://gist.github.com/mattallan/fd52629eae293540c6d8)

Subscriptions

This section lists all API that can be used to create, edit or otherwise manipulate subscriptions.

Subscription Properties

Attribute Type Description
id integer Subscription ID (post ID) read-only
order_number integer Order number read-only