Skip to content

Instantly share code, notes, and snippets.

View devinsays's full-sized avatar

Devin Price devinsays

View GitHub Profile
@devinsays
devinsays / wc-footer-conversion-tracking-example.php
Last active July 18, 2023 14:27
Example of WooCommerce Conversion Tracking in wp_footer
@devinsays
devinsays / update-product-prices.php
Last active June 5, 2023 20:01
Updates product prices via WP CLI script.
<?php
/**
* Updates product prices.
* More about WP CLI scripts:
* https://wptheming.com/2021/05/wp-cli-scripts-and-woocommerce/
*
* wp eval-file update-product-prices.php
*/
$products = get_posts([
@devinsays
devinsays / customizer-controls-40
Last active April 20, 2023 10:03
WordPress 4.0 Customizer Controls
function prefix_customizer_register( $wp_customize ) {
$wp_customize->add_panel( 'panel_id', array(
'priority' => 10,
'capability' => 'edit_theme_options',
'theme_supports' => '',
'title' => __( 'Example Panel', 'textdomain' ),
'description' => __( 'Description of what this panel does.', 'textdomain' ),
) );
@devinsays
devinsays / ActionSchedulerHighVolume.php
Last active March 24, 2023 14:25
Modifications to Action Scheduler in order to run higher volumes of actions.
<?php
/**
* High volume modifications to Action Scheduler.
*
* Adapted from https://github.com/woocommerce/action-scheduler-high-volume/
*
* Increase Action Scheduler batch size, concurrency, timeout period, and claim action query
* ORDER BY to process large queues of actions more quickly on servers with more server resources.
*
* @package UniversalYums\ActionScheduler
@devinsays
devinsays / update-coupon-data.php
Created February 25, 2023 20:11
Updates coupon data in the verification table for WooCommerce Coupon Restrictions
<?php
/**
* Workaround to load historic data if WP CLI is not installed.
* Update the $code variable to match the coupon code you want to update.
*
* This code can be loaded in a custom plugin or in your theme's functions.php file.
*
* A transient is used to prevent the data from being updated more than once,
* but this code should be removed as soon as it has run and the table is updated.
*/
@devinsays
devinsays / estimate-read-time.php
Last active February 11, 2023 20:57
WordPress Estimated Read Time
<?php
/**
* Estimates the reading time for a given piece of $content.
*
* @param string $content Content to calculate read time for.
* @param int $wpm Estimated words per minute of reader.
*
* @returns int $time Esimated reading time.
*/
function prefix_estimated_reading_time( $content = '', $wpm = 300 ) {
@devinsays
devinsays / delete-fraud-activity-by-ip.php
Created May 7, 2021 16:52
Deleted WooCommerce orders, subscriptions, and customers based on the IP address used to order.
<?php
/**
* This script will delete all `on-hold` subscriptions and their orders and users.
* It will delete all subscriptions based on IP.
*
* wp eval-file delete-fraud-activity-by-ip.php 127.0.0.1
*
* Dry run:
* wp eval-file delete-fraud-activity-by-ip 127.0.0.1 dry
*
<?php
/**
* Some meta data should not be copied to subscriptions or renewal orders.
*/
namespace UniversalYums\Subscriptions;
class PreventMetaCopy {
/**
@devinsays
devinsays / OrdersList.php
Created June 2, 2022 15:45
Speeds up the loading of /wp-admin/edit.php?post_type=shop_order and /wp-admin/edit.php?post_type=subscription.
<?php
namespace UniversalYums\Admin\Performance;
class OrdersList {
/**
* The single instance of the class.
*/
protected static $instance;
@devinsays
devinsays / schedule-products-sale.php
Created November 23, 2022 16:47
WP CLI script schedule a product sale in WooCommerce.
<?php
/**
* WP CLI script to schedule a sale for specific dates.
*
* To support scheduled sales to the hour/minute, use this free plugin:
* https://wordpress.org/plugins/precise-sales-for-woocommerce/
*
* wp eval-file schedule-products-sale.php
*/
if ( ! defined( 'ABSPATH' ) ) {