Skip to content

Instantly share code, notes, and snippets.

@justinstern
justinstern / functions.php
Last active July 14, 2021 17:22
This snippet will disable WooCommerce core emails based on the product category
<?php
// Add the below to the bottom of your theme's functions.php:
add_filter( 'woocommerce_email_enabled_customer_processing_order', 'disable_emails_for_fundraising', 10, 2 );
add_filter( 'woocommerce_email_enabled_customer_completed_order', 'disable_emails_for_fundraising', 10, 2 );
function disable_emails_for_fundraising( $enabled, $order ) {
if ( isset( $order ) && count( $order->get_items() ) > 0 ) {
@justinstern
justinstern / sample-orders-metadata.json
Last active June 27, 2020 03:40
taken from: select properties from orders where properties is not null and platform_name != 'edd' limit 100;
{"tracking": [{"tracking_id": "2ba66a14505f97de0e5a2b1672186aa7", "date_shipped": "1593129600", "tracking_number": "40417300001301", "tracking_provider": "dhl-parcel-uk", "formatted_tracking_link": "https://track.dhlparcel.co.uk/?con=40417300001301", "formatted_tracking_provider": "DHL Parcel UK"}], "tracking_code": "40417300001301"}
{"tracking_code": "9400136205309524568071"}
{"time": "14:30", "datum": "04.06.2020"}
{"notes": ["Glock 23 Drop In Ultra Match Barrel (G23-Thread-TiN) x 1 shipped via USPS on June 16, 2020 with tracking number 9405511899563517863014."]}
EDD:
@justinstern
justinstern / sample-orders-metadata.json
Created June 27, 2020 03:40
taken from: select properties from orders where properties is not null and platform_name != 'edd' limit 100;
{"tracking": [{"tracking_id": "2ba66a14505f97de0e5a2b1672186aa7", "date_shipped": "1593129600", "tracking_number": "40417300001301", "tracking_provider": "dhl-parcel-uk", "formatted_tracking_link": "https://track.dhlparcel.co.uk/?con=40417300001301", "formatted_tracking_provider": "DHL Parcel UK"}], "tracking_code": "40417300001301"}
{"tracking_code": "9400136205309524568071"}
{"time": "14:30", "datum": "04.06.2020"}
{"notes": ["Glock 23 Drop In Ultra Match Barrel (G23-Thread-TiN) x 1 shipped via USPS on June 16, 2020 with tracking number 9405511899563517863014."]}
@justinstern
justinstern / wc-nested-category-layout-hide-cat-images.php
Created April 21, 2014 18:40
WooCommerce Nested Category Layout: hide the subcategory image in the nested categories layout.
<?php
// Add the code below to the bottom of your current theme's functions.php:
function woocommerce_nested_category_products_content_section( $categories, $product_category_ids ) {
global $wp_query, $wc_nested_category_layout;
$title = '';
$term = '';
@justinstern
justinstern / wc-email-recipient-for-payment-type.php
Created April 23, 2014 16:38
WooCommerce New Order email alert based on payment type. This snippet will send a new order alert email to an additional email address, based on payment type. Reader question from http://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
<?php
// Add everything below to your current theme's functions.php:
// The email to send can be changed by using a different filter in place of 'woocommerce_email_recipient_new_order'
// The payment method can be changed by using a different payment method id in place of 'cod'
add_filter( 'woocommerce_email_recipient_new_order', 'wc_new_order_cash_on_delivery_recipient', 10, 2 );
function wc_new_order_cash_on_delivery_recipient( $recipient, $order ) {
<?php
// This sample code will add additional recipients to a WooCommerce email order type, based on the order email address
// Email id's for the various email types (i.e. customer_invoice) can be found here:
// https://github.com/woothemes/woocommerce/blob/5e09f15c91970d8bec4ab56abbfd5d3039a02a1b/includes/emails/class-wc-email-customer-invoice.php#L30https://github.com/woothemes/woocommerce/blob/5e09f15c91970d8bec4ab56abbfd5d3039a02a1b/includes/emails/class-wc-email-customer-invoice.php#L30
// Add the following to the bottom of your theme's functions.php:
add_filter( 'woocommerce_email_recipient_customer_invoice', 'woocommerce_email_customer_invoice_add_recipients' );
function woocommerce_email_customer_invoice_add_recipients( $recipient, $order ) {
if ( 'joe@acme.com' == $recipient ) {
@justinstern
justinstern / wc-order-email-payment-instructions.php
Last active August 22, 2017 14:28
Adding some payment instructions to WooCommerce order processing email
<?php
// Add the following to your theme's functions.php:
add_action( 'woocommerce_order_status_pending_to_processing_notification', 'watch_for_processing_email', 5 );
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', 'watch_for_processing_email', 5 );
function watch_for_processing_email() {
// only add the instructions for processing type emails
add_action( 'woocommerce_email_before_order_table', 'add_order_email_instructions', 10, 2 );
@justinstern
justinstern / wc-pdf-product-vouchers-custom-voucher-number.php
Created March 19, 2014 19:12
An example of how to create and use a randomized voucher number like 4ST0P-TGIBC-ZBBGU-VNQ8A with the WooCommerce PDF Product Vouchers plugin
<?php
// Create and use a randomized voucher number
function serial_p4u( $number, $voucher ) {
// if we've already generated a custom voucher number, get it and return it
if ( $voucher->get_item_id() ) {
$custom_serial = wc_get_order_item_meta( $voucher->get_item_id(), '_voucher_custom_number', true );
if ( $custom_serial ) {
return $custom_serial;
<?php
// add the following to the bottom of your functions.php
// assumes a copy of the core class-wc-shortcodes.php, customized, is available at path/to/custom/class-wc-shortcodes.php
add_action( 'woocommerce_loaded', 'use_custom_wc_shortcodes' );
function use_custom_wc_shortcodes() {
// load our custom shortcodes class
@justinstern
justinstern / wc-pdf-product-vouchers-custom-fields.php
Last active May 2, 2017 20:40
Sample code demonstrating how to create custom voucher fields for with the WooCommerce PDF Product Vouchers plugin
<?php
// Put the following in your theme's functions.php for instance:
add_filter( 'wc_pdf_product_vouchers_voucher_fields', 'wc_pdf_product_vouchers_add_custom_fields', 10, 2 );
/**
* Adds some custom fields to the given product voucher
*