Skip to content

Instantly share code, notes, and snippets.

Avatar

Devin Price devinsays

View GitHub Profile
@devinsays
devinsays / update-product-prices.php
Last active May 31, 2021
Updates product prices via WP CLI script.
View update-product-prices.php
<?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 / export-product-data.php
Last active May 31, 2021
WooCommerce Export Product Data
View export-product-data.php
<?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-fraud-activity-by-ip.php
Created May 7, 2021
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
*
@devinsays
devinsays / challenge.md
Last active May 18, 2021
WooCommerce MySQL Challenge
View challenge.md

Here's a couple MySQL challenges. No tricks or gotchas, just straightforward MySQL queries.

We generally use TablePlus when making SQL queries, but you can also use the command line or whatever you're most comfortable with.

Here's an example query to get all orders on WooCommerce site:

SELECT
	*
FROM
View PreventMetaCopy.php
<?php
/**
* Some meta data should not be copied to subscriptions or renewal orders.
*/
namespace UniversalYums\Subscriptions;
class PreventMetaCopy {
/**
@devinsays
devinsays / TagToMeta.php
Created Jan 27, 2021
Saves taxonomy terms to product meta in a comma separated list
View TagToMeta.php
<?php
namespace UniversalYums\TagToMeta;
class TagToMeta {
/**
* The single instance of the class.
*/
protected static $instance;
@devinsays
devinsays / active-subscribers.sql
Created Nov 5, 2020
active-subscriber-ids.sql
View active-subscribers.sql
/*
* MySQL query to run site running WooCommerce Subscriptions.
* Selects all user ids for customers with an active subscriptions.
*/
select
meta.meta_value as user_id
from
wp_qftw_posts posts
left join wp_qftw_postmeta meta ON meta.post_ID = posts.ID
where
@devinsays
devinsays / wc-product.sql
Last active Aug 21, 2020
SQL: Get WooCommerce Product ID, title, SKU, and Image
View wc-product.sql
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 / svg-icon-post.md
Last active May 27, 2021
How to Use an SVG for a Custom Post Type Icon
View svg-icon-post.md

Let's use this id-card svg for the custom post type icon rather than a standard dashicon.

First, download the raw SVG file. If you open it up in a text editor, it should look something like this:

<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="id-card" class="svg-inline--fa fa-id-card fa-w-18" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M528 32H48C21.5 32 0 53.5 0 80v16h576V80c0-26.5-21.5-48-48-48zM0 432c0 26.5 21.5 48 48 48h480c26.5 0 48-21.5 48-48V128H0v304zm352-232c0-4.4 3.6-8 8-8h144c4.4 0 8 3.6 8 8v16c0 4.4-3.6 8-8 8H360c-4.4 0-8-3.6-8-8v-16zm0 64c0-4.4 3.6-8 8-8h144c4.4 0 8 3.6 8 8v16c0 4.4-3.6 8-8 8H360c-4.4 0-8-3.6-8-8v-16zm0 64c0-4.4 3.6-8 8-8h144c4.4 0 8 3.6 8 8v16c0 4.4-3.6 8-8 8H360c-4.4 0-8-3.6-8-8v-16zM176 192c35.3 0 64 28.7 64 64s-28.7 64-64 64-64-28.7-64-64 28.7-64 64-64zM67.1 396.2C75.5 370.5 99.6 352 128 352h8.2c12.3 5.1 25.7 8 39.8 8s27.6-2.9 39.8-8h8.2c28.4 0 52.5 18.5
View tracking.php
<?php
/**
* Add GTM ecommerce tracking to the Order Complete (Thank You) page.
*
* @param int $order_id
*/
public function thank_you_tracking($order_id)
{
$user_id = get_current_user_id();
$is_existing_customer = $user_id ? get_user_meta($user_id, '_existing_customer', true) : false;