Last active
November 3, 2017 07:13
-
-
Save kartikparmar/c93a37c69580eecc3add4e7194aa59bc to your computer and use it in GitHub Desktop.
Saving the value when product is published/updated
This file contains 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 | |
/* | |
* This function will save the value set to Minimum Quantity and Maximum Quantity options | |
* into _wc_min_qty_product and _wc_max_qty_product meta keys respectively | |
*/ | |
function wc_qty_save_product_field( $post_id ) { | |
$val_min = trim( get_post_meta( $post_id, '_wc_min_qty_product', true ) ); | |
$new_min = sanitize_text_field( $_POST['_wc_min_qty_product'] ); | |
$val_max = trim( get_post_meta( $post_id, '_wc_max_qty_product', true ) ); | |
$new_max = sanitize_text_field( $_POST['_wc_max_qty_product'] ); | |
if ( $val_min != $new_min ) { | |
update_post_meta( $post_id, '_wc_min_qty_product', $new_min ); | |
} | |
if ( $val_max != $new_max ) { | |
update_post_meta( $post_id, '_wc_max_qty_product', $new_max ); | |
} | |
} | |
add_action( 'woocommerce_process_product_meta', 'wc_qty_save_product_field' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment