Skip to content

Instantly share code, notes, and snippets.

@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-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-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-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-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-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-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-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-catalog-lightbox.php
Created November 25, 2013 04:02
Display a lightbox of the product catalog image, rather than linking to the product page. Drop this code snippet into the bottom of your theme's functions.php file. Implementation note: at line 25 we're stripping the image dimensions out of the original image source in order to try and display the full sized image. So if the catalog thumbnail is…
<?php
// Code to display catalog images in a lightbox follows:
add_action( 'wp_enqueue_scripts', 'frontend_scripts_include_lightbox' );
function frontend_scripts_include_lightbox() {
global $woocommerce;
if ( is_shop() || is_product_category() ) {
@justinstern
justinstern / wc-elavon-vm-custom-params.php
Created November 12, 2013 22:39
Sample code for adding a custom parameter to the WooCommerce Elavon VM Payment Gateway transaction request. This is most useful when a custom field is required on an account. Simply add the following to the bottom of your theme's functions.php, including whatever custom parameters your account setup requires
<?php
add_filter( 'wc_payment_gateway_elavon_vm_request_xml', 'wc_payment_gateway_elavon_vm_add_custom_fields', 10, 2 );
function wc_payment_gateway_elavon_vm_add_custom_fields( $request_xml, $request ) {
$request_xml->addChild( 'ssl_name_on_card', str_replace( array( '&', '<', '>' ), '', $request->ssl_first_name . ' ' . $request->ssl_last_name ) );
return $request_xml;
}