Skip to content

Instantly share code, notes, and snippets.

@Langmans
Created June 4, 2015 12:44
Show Gist options
  • Save Langmans/1682a8e531fab95718e2 to your computer and use it in GitHub Desktop.
Save Langmans/1682a8e531fab95718e2 to your computer and use it in GitHub Desktop.
jQuery(function ($) {
var sku_fields = '[name^="variable_sku"]',
display_class = 'variation_sku_display',
warning_display = true;
$('body').on('input', sku_fields, function () {
var $input = $(this), sku = this.value,
$variation = $input.closest('.woocommerce_variation'),
$display = $('.' + display_class, $variation);
if (!$display.length) {
$display = $('<span />', {class: display_class})
.css({
fontWeight: 'normal'//,
//float: 'right'
})
.insertAfter($('.remove_variation', $variation));
}
if (sku.length) {
$display.html('<strong>SKU:</strong> ' + sku + ' — ');
} else {
$display.hide();
}
if (!$display.parent().length && warning_display) {
alert('The plugin woocommerce-SKUs is not compatible with this woocommerce version. The tab structure for product variations probably changed. Please contact Dragon Media Group.');
}
}).find(sku_fields).trigger('input');
});
<?php
/*
Plugin Name: Woocommerce SKU display
Description: Shows the SKU next to a variation.
Author: Ruben Vincenten | Dragon Media Group B.V.
Version: 1.0
Author URI: http://dragonmediagroup.nl
*/
// directory should contain this file + a js file.
add_action( 'woocommerce_product_data_panels', function () {
if(is_admin()) {
wp_enqueue_script( 'woocommerce-skus', plugin_dir_url( __FILE__ ) . '/sku-display.js', array(
'jquery',
'wc-admin-variation-meta-boxes'
), 1.0, true );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment