Skip to content

Instantly share code, notes, and snippets.

View thenbrent's full-sized avatar

Brent Shepherd thenbrent

View GitHub Profile
@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 / 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 / enable-debug.php
Last active September 4, 2018 03:38
Mini-plugin to enable WP_DEBUG, WP_DEBUG_DISPLAY, & WP_DEBUG_LOG on a site where not FTP/SFTP access is available.
<?php
/**
* Plugin Name: Enable WP_DEBUG
* Plugin URI: https://gist.github.com/thenbrent/d319cd9eaa88faea5cb69d296ea8ccc1
* Description: Enable WP_DEBUG, WP_DEBUG_DISPLAY, & WP_DEBUG_LOG on a site where not FTP/SFTP access is available.
* Author: Prospress Inc.
* Version: 1.0
* Author URI: http://prospress.com
*
* Copyright 2017 Prospress, Inc. (email : [email protected])
@thenbrent
thenbrent / test-date-default-timezone-set.php
Created December 7, 2016 20:23
Demonstrate impact of date_default_timezone_set()
<?php
$date_string = '2015-11-13 09:59:00';
// Normal WordPress Way
date_default_timezone_set( 'UTC' );
$date_utc = new DateTime( $date_string );
// Rare Occassions
date_default_timezone_set( 'America/Los_Angeles' );
@thenbrent
thenbrent / wcs-mod-display.php
Created October 5, 2016 00:21
Prepend "With Failure" to subscriptions with the "on-hold" status and the last renewal order with the "failed" status.
<?php
/**
* Plugin Name: WooCommerce Subscriptions - Display Failed Status
* Plugin URI:
* Description: Prepend "With Failure" to subscriptions with the "on-hold" status and the last renewal order with the "failed" status.
* Author: Prospress Inc.
* Author URI: http://prospress.com/
* Version: 1.0
*
* Copyright 2016 Prospress, Inc. (email : [email protected])
@thenbrent
thenbrent / wcs-calculate-next-payment-from-last-payment.md
Last active November 16, 2016 00:06
By default, WooCommerce Subscriptions will calculate the next payment date for a subscription from the time of the last payment. This plugin changes that to preserve the original schedule and calculate the next payment date from the scheduled payment date, not the time the payment was actually processed. For example, without this plugin, the due…

This gist has been migrated to a repo here.

@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 / bs-debugging-helpers.php
Last active September 9, 2019 06:43
A few handy functions for debugging PHP script execution in WordPress/WooCommerce.
<?php
/**
* Plugin Name: Brent's Debugging Helpers
* Plugin URI:
* Description: bs_backtrace() etc.
* Version: 8.13.21
* Author:
* Author URI:
*/
@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
@thenbrent
thenbrent / wcs-test-retry-rules.php
Last active September 8, 2020 14:02
WooCommerce Subscriptions Failed Payment Retry Rules for Testing: Replace the default WooCommerce Subscriptions failed payment retry rules with rules that run every few minutes (not days) and always send dunning emails to help with testing.
<?php
/**
* Plugin Name: WooCommerce Subscriptions Failed Payment Retry Rules for Testing
* Plugin URI:
* Description: Replace the default WooCommerce Subscriptions failed payment retry rules with rules that run every few minutes (not days) and always send dunning emails to help with testing.
* Author: Prospress Inc.
* Author URI: http://prospress.com/
* Version: 1.0
*
* Copyright 2016 Prospress, Inc. (email : [email protected])