Skip to content

Instantly share code, notes, and snippets.

@justinstern
justinstern / wc-pdf-product-vouchers-voucher-number-on-admin-email.php
Created December 5, 2013 23:06
Display any voucher numbers from voucher items in the order on the New Order admin email. To use this snippet simply paste into the bottom of your theme's functions.php
<?php
// Displays any voucher numbers on the New Order admin email
add_action( 'woocommerce_email_order_meta', function( $order, $is_admin ) {
if ( $is_admin ) {
$voucher_numbers = array();
$order_items = $order->get_items();
@justinstern
justinstern / wc-tab-manager-category-tab.php
Created December 27, 2013 05:40
Sample code for the WooCommerce Tab Manager plugin to conditionally display a tab based on the product category. To use this code, first go to WooCommerce > Tab Manager > Add Global Tab and create a new global tab, which for this example we'll name "Sample Tab". "Sample Tab" will now show up for every product that uses the global tab layout. Let…
<?php
add_filter( 'wc_tab_manager_product_tabs', 'wc_tab_manager_product_tabs' );
function wc_tab_manager_product_tabs( $tabs ) {
global $product;
foreach ( $tabs as $tab_name => $tab ) {
@justinstern
justinstern / wc-admin-custom-order-fields-dynamic-options.php
Created February 7, 2014 04:09
An example of using the WooCommerce Admin Custom Order Fields 'wc_admin_custom_order_field_options' filter to return a dynamic set of options. In this sample we're pulling all WordPress terms, for the field which we have named "From Database". Options could be pulled from any other database/table, remote service, or anywhere! To use this code, c…
<?php
/*
* Returns a set of admin custom order field options from the database, rather
* than as configured by the admin
*/
add_filter( 'wc_admin_custom_order_field_options', function( $options, $field ) {
global $wpdb;
@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-flat-rate-custom-label.php
Created March 11, 2014 05:43
Put this code snippet at the bottom of your theme's functions.php to modify the flat rate shipping label from (Free) to (will be calculated)
<?php
add_filter( 'woocommerce_cart_shipping_method_full_label', 'woocommerce_flat_rate_custom_label', 10, 2 );
function woocommerce_flat_rate_custom_label( $label, $method ) {
if ( 'flat_rate' == $method->id && 0 == $method->cost ) {
$label = $method->label . ' (will be calculated)';
}
return $label;
}
@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;
@justinstern
justinstern / wc-tab-manager-global-tab-product-specific-content.php
Last active August 29, 2015 13:59
Sample code to demonstrate the display of product-specific content for a global tab with the WooCommerce Tab Manager plugin http://www.woothemes.com/products/woocommerce-tab-manager/ The content is taken from a Custom Field named 'product_specifications_tab_content' added to the product. This assumes that the product is using the Global Tab Layo…
<?php
// Add everything below to your current theme's functions.php file
add_filter( 'woocommerce_tab_manager_tab_panel_content', 'wc_tab_manager_global_tab_product_specific_content', 10, 3 );
function wc_tab_manager_global_tab_product_specific_content( $content, $tab, $product ) {
// tab by title slug
if ( 'product-specifications' == $tab['name'] ) {
@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 ) {
@justinstern
justinstern / wc-measurement-price-calculator-hide-prices.php
Created May 23, 2014 16:17
WC Measurement Price Calculator customization to hide the product price per unit http://www.woothemes.com/products/measurement-price-calculator/
<?php
// Add the following to the bottom of your current theme's functions.php
add_filter( 'woocommerce_sale_price_html', 'remove_price_per_unit_html', 15, 2 );
add_filter( 'woocommerce_price_html', 'remove_price_per_unit_html', 15, 2 );
add_filter( 'woocommerce_empty_price_html', 'remove_price_per_unit_html', 15, 2 );
add_filter( 'woocommerce_variable_sale_price_html', 'remove_price_per_unit_html', 15, 2 );
add_filter( 'woocommerce_variable_price_html', 'remove_price_per_unit_html', 15, 2 );
add_filter( 'woocommerce_variable_empty_price_html', 'remove_price_per_unit_html', 15, 2 );