Created
November 14, 2015 07:47
-
-
Save Deaner666/998b641bf357a46f100c to your computer and use it in GitHub Desktop.
Save the WooCommerce product_cat details meta field passed by the add or edit category page
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 | |
add_action( 'create_product_cat', 'wpm_product_cat_details_meta_save' ); | |
add_action( 'edit_product_cat', 'wpm_product_cat_details_meta_save' ); | |
/** | |
* Save Product Category details meta. | |
* | |
* Save the product_cat details meta POSTed from the | |
* edit product_cat page or the add product_cat page. | |
* | |
* @param int $term_id The term ID of the term to update. | |
*/ | |
function wpm_product_cat_details_meta_save( $term_id ) { | |
if ( ! isset( $_POST['wpm_product_cat_details_nonce'] ) || ! wp_verify_nonce( $_POST['wpm_product_cat_details_nonce'], basename( __FILE__ ) ) ) { | |
return; | |
} | |
$old_details = get_term_meta( $term_id, 'details', true ); | |
$new_details = isset( $_POST['wpm-product-cat-details'] ) ? $_POST['wpm-product-cat-details'] : ''; | |
if ( $old_details && '' === $new_details ) { | |
delete_term_meta( $term_id, 'details' ); | |
} else if ( $old_details !== $new_details ) { | |
update_term_meta( | |
$term_id, | |
'details', | |
wpm_sanitize_details( $new_details ) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment