Skip to content

Instantly share code, notes, and snippets.

Avatar

Devin Price devinsays

View GitHub Profile
@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.
View delete-fraud-activity-by-ip.php
<?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
*
View PreventMetaCopy.php
<?php
/**
* Some meta data should not be copied to subscriptions or renewal orders.
*/
namespace UniversalYums\Subscriptions;
class PreventMetaCopy {
/**
@devinsays
devinsays / delete-completed-order-meta.php
Created December 28, 2022 18:18
Deletes meta data from completed orders created more than 90 days ago.
View delete-completed-order-meta.php
<?php
/**
* Delete postmeta for completed orders created more than X days ago.
*
* To delete meta on completed orders run:
* wp eval-file delete-completed-order-meta.php
*/
// Transient allows the script to resume where it left off if interrupted.
$transient_name = 'last_processed_order';
@devinsays
devinsays / ActionSchedulerHighVolume.php
Last active January 23, 2023 13:24
Modifications to Action Scheduler in order to run higher volumes of actions.
View ActionSchedulerHighVolume.php
<?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 / new-customer-coupon.php
Created January 4, 2016 04:56
Example for WooCommerce unit tests.
View new-customer-coupon.php
<?php
namespace WooCommerce\Tests\New_Customer_Coupon;
/**
* Class New_Customer_Coupon.
* @package WooCommerce\Tests\New_Customer_Coupon
*/
class New_Customer_Coupon extends \WC_Unit_Test_Case {
@devinsays
devinsays / estimate-read-time.php
Last active December 6, 2022 09:19
WordPress Estimated Read Time
View estimate-read-time.php
<?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 / 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.
View OrdersList.php
<?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.
View schedule-products-sale.php
<?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' ) ) {
@devinsays
devinsays / coupon-generator.php
Last active November 2, 2022 22:14
WP CLI script for generating coupon copies
View coupon-generator.php
<?php
/**
* Generate coupon copies from an existing coupon.
* Replaces UNQCODE with a unique generated coupon code.
*
* For more information about this script:
* https://devpress.com/wp-cli-script-to-duplicate-woocommerce-coupons/
*
* wp eval-file coupon-generator.php
*/
@devinsays
devinsays / sync-config.sh
Created October 21, 2022 21:31
Bash script for syncing WP Engine production to local
View sync-config.sh
sshenv=yoursite
replace=('yoursite.com' 'yoursite.local')