Skip to content

Instantly share code, notes, and snippets.

@Deaner666

Deaner666/functions.php

Last active Aug 29, 2015
Embed
What would you like to do?
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