Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add product SKU column before item (title) column on an order form from Order Form for WooCommerce. Requires version 1.4.0 or higher. Save this file as a simple plugin in the WordPress plugins folder. http://orderform-woo.webaware.net.au/
<?php
/*
Plugin Name: Order Form for WooCommerce SKU
Plugin URI: https://gist.github.com/webaware/a75e83ede1607536642b
Description: add product SKU column to Order Form for WooCommerce product
Author: WebAware
Author URI: http://webaware.com.au/
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* add column head for SKU
* @param array $attrs
*/
add_action('orderform_woocommerce_before_order_item_head', function($attrs) {
?>
<th class="orderform-woocommerce-order-sku">SKU</th>
<?php
});
/**
* add column foot for SKU
* @param array $attrs
*/
add_action('orderform_woocommerce_before_order_item_foot', function($attrs) {
?>
<td class="orderform-woocommerce-order-sku">&nbsp;</td>
<?php
});
/**
* add column for SKU
* @param array $attrs
*/
add_action('orderform_woocommerce_before_order_item', function($product, $attrs) {
$sku = wc_product_sku_enabled() ? $product->get_sku() : '';
?>
<td class="orderform-woocommerce-order-sku">
<span class="sku" itemprop="sku"><?php echo $sku; ?></span>
</td>
<?php
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.