Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Created November 19, 2020 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codearachnid/cf91fc4307317ed169ff5aa380d0b577 to your computer and use it in GitHub Desktop.
Save codearachnid/cf91fc4307317ed169ff5aa380d0b577 to your computer and use it in GitHub Desktop.
Needed a quick drop in script for functions.php to add SKU field on the general tab within WooCommerce product editor
<?php
// add sku on woocommerce product editor >> general tab
add_action( 'woocommerce_product_options_general_product_data', 'add_the_sku_to_general_product_field' );
function add_the_sku_to_general_product_field() {
global $post;
$product_sku = get_post_meta( $post->ID, '_sku', true );
?>
<div class="options_group">
<p class="form-field _sku_field ">
<label for="_sku">
<abbr title="Stock Keeping Unit">SKU</abbr>
</label>
<!--<span class="woocommerce-help-tip"></span>-->
<input type="text" class="short" style="" name="_sku" id="_sku_alias" value="<?php echo $product_sku; ?>" placeholder=""
onchange="(function(){
jQuery('input#_sku').val(jQuery('input#_sku_alias').val());
})();" >
</p>
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment