WC_Product_Variable::sync_stock_status
Sync parent stock status with the status of all children and save.
Метод класса: WC_Product_Variable{}
Хуков нет.
Возвращает
WC_Product. Synced product object.
Использование
$result = WC_Product_Variable::sync_stock_status( $product, $save );
- $product(WC_Product|int) (обязательный)
- Product object or ID for which you wish to sync.
- $save(true|false)
- If true, the product object will be saved to the DB before returning it.
По умолчанию: true
Код WC_Product_Variable::sync_stock_status() WC Product Variable::sync stock status WC 10.3.5
public static function sync_stock_status( $product, $save = true ) {
if ( ! is_a( $product, 'WC_Product' ) ) {
$product = wc_get_product( $product );
}
if ( is_a( $product, 'WC_Product_Variable' ) ) {
$data_store = WC_Data_Store::load( 'product-' . $product->get_type() );
$data_store->sync_stock_status( $product );
if ( $save ) {
$product->save();
}
}
return $product;
}