Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Forked from digitalchild/functions.php
Created June 14, 2016 00:07
Show Gist options
  • Save bentasm1/85e3b923bec8383035bffcf66677fccf to your computer and use it in GitHub Desktop.
Save bentasm1/85e3b923bec8383035bffcf66677fccf to your computer and use it in GitHub Desktop.
Force stock qty to 1 with no backorders
<?php
add_action( 'wcv_save_product_meta', 'wcv_custom_stock_opts' );
function wcv_custom_stock_opts( $post_id ) {
update_post_meta( $post_id, '_manage_stock', 'yes' );
update_post_meta( $post_id, '_backorders', 'no' );
wc_update_product_stock( $post_id, wc_stock_amount( 1 ) );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment