Skip to content

Instantly share code, notes, and snippets.

@Deaner666
Last active August 29, 2015 14:07
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 Deaner666/43206993c1feb6777dfc to your computer and use it in GitHub Desktop.
Save Deaner666/43206993c1feb6777dfc to your computer and use it in GitHub Desktop.
Save custom meta on creation and edit of a WooCommerce product_cat
<?php
// Save extra taxonomy fields callback function
add_action( 'edited_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
add_action( 'create_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
function save_taxonomy_custom_meta( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][$key] ) ) {
$term_meta[$key] = wp_kses_post( stripslashes($_POST['term_meta'][$key]) );
}
}
// Save the option array.
update_option( "taxonomy_$t_id", $term_meta );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment