Skip to content

Instantly share code, notes, and snippets.

@luizbills
Created September 27, 2018 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luizbills/bc9a64cdb047ddad7e69d01833a1d791 to your computer and use it in GitHub Desktop.
Save luizbills/bc9a64cdb047ddad7e69d01833a1d791 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