Last active
August 29, 2015 14:07
-
-
Save Deaner666/43206993c1feb6777dfc to your computer and use it in GitHub Desktop.
Save custom meta on creation and edit of a WooCommerce product_cat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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