Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View devinsays's full-sized avatar

Devin Price devinsays

View GitHub Profile
@devinsays
devinsays / delete-customers-without-orders.php
Created January 13, 2024 19:45
Deletes users with customer role in WooCommerce that do not have orders.
<?php
/**
* Deletes customers without orders
*
* To run the script:
* wp eval-file delete-customers-without-orders.php
*/
// Query for customers registered since this date.
$date_after = '2000-01-01';
@devinsays
devinsays / class-metabox.php
Last active September 2, 2023 19:09
WooCommerce: Add metabox the order page. Support for HPOS (High Performance Order Storage)
<?php
namespace Your_Namespace;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
/**
* Class Metabox.
*
* Example for how to add a metabox to the order screen that supports both HPOS and legacy order storage.
* More information: https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book#audit-for-order-administration-screen-functions
@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 / delete-completed-order-meta.php
Created December 28, 2022 18:18
Deletes meta data from completed orders created more than 90 days ago.
<?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 / 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' ) ) {
@devinsays
devinsays / coupon-generator.php
Last active February 17, 2024 22:58
WP CLI script for generating coupon copies
<?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
sshenv=yoursite
replace=('yoursite.com' 'yoursite.local')
@devinsays
devinsays / .gitignore
Created October 19, 2022 02:57
GitIgnore Example for WooCommerce
# Filetypes
*.sql
debug.log
.DS_Store
# Directories
node_modules/
/tmp/
/vendor/
@devinsays
devinsays / channel-logic.php
Last active October 4, 2022 19:51
Fulfil channel logic
<?php
/**
* Determine which Fulfil channel ID to use based on order type, source.
*
* @param Order $order Order to check
*
* @return mixed
*/
public static function getChannelId(Order $order)
{
@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;