Skip to content

Instantly share code, notes, and snippets.

View devinsays's full-sized avatar

Devin Price devinsays

View GitHub Profile
@devinsays
devinsays / new-customer-coupon.php
Created January 4, 2016 04:56
Example for WooCommerce unit tests.
<?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 / performance.php
Created November 19, 2021 18:17
Dequeue scripts and styles
<?php
namespace DevPress\Frontend;
/**
* Class Performance
*
* @package DevPress\Performance
*/
class Performance {
@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 / 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 / export-product-data.php
Last active February 15, 2024 19:39
WooCommerce Export Product Data
<?php
/**
* Exports product data.
*
* More about WP CLI scripts:
* https://wptheming.com/2021/05/wp-cli-scripts-and-woocommerce/
*
* wp eval-file export-product-data.php
*/
@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 / wc-product.sql
Last active December 1, 2023 13:15
SQL: Get WooCommerce Product ID, title, SKU, and Image
SELECT
products.id,
products.post_title as title,
meta3.meta_value as sku,
meta2.meta_value as image_url
FROM
wp_qftw_posts products
LEFT JOIN
wp_qftw_postmeta meta1
ON (
@devinsays
devinsays / set-cookie-wordpress.php
Last active November 13, 2023 13:04
How to set a cookie using PHP in WordPress
@devinsays
devinsays / example-ajax-enqueue.php
Last active October 4, 2023 13:09
Simple WordPress Ajax Example
<?php
function example_ajax_enqueue() {
// Enqueue javascript on the frontend.
wp_enqueue_script(
'example-ajax-script',
get_template_directory_uri() . '/js/simple-ajax-example.js',
array( 'jquery' )
);
@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