-
-
Save odirlon/d8430720c8bf7da719b7abdfa393ace8 to your computer and use it in GitHub Desktop.
Disable 'manage_stock' in REST API for variable products
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 | |
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