Skip to content

Instantly share code, notes, and snippets.

@odirlon
Forked from luizbills/code.php
Created September 27, 2018 18:42
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 odirlon/d8430720c8bf7da719b7abdfa393ace8 to your computer and use it in GitHub Desktop.
Save odirlon/d8430720c8bf7da719b7abdfa393ace8 to your computer and use it in GitHub Desktop.
Disable 'manage_stock' in REST API for variable products
<?php
add_filter( 'woocommerce_rest_pre_insert_product_object', 'lpb_wc_disable_magage_stock_in_rest_api', 10, 2 );
function lpb_wc_disable_magage_stock_in_rest_api ( $product, $request ) {
if ( 'yes' === get_option( 'woocommerce_manage_stock' ) && $product->is_type( 'variable' ) ) {
if ( isset( $request['manage_stock'] ) && $request['manage_stock'] ) {
unset( $request['manage_stock'] );
$product->set_manage_stock( false );
}
}
return $product;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment