Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Last active November 3, 2017 07:13
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 kartikparmar/c93a37c69580eecc3add4e7194aa59bc to your computer and use it in GitHub Desktop.
Save kartikparmar/c93a37c69580eecc3add4e7194aa59bc to your computer and use it in GitHub Desktop.
Saving the value when product is published/updated
<?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