WordPress at a glance
function is not described

wc_maybe_reduce_stock_levels() WC 3.0.0

When a payment is complete, we can reduce stock levels for items within an order.

Return

null. Nothing.

Usage

wc_maybe_reduce_stock_levels( $order_id );
$order_id(int) (required)
Order ID.

Changelog

Since 3.0.0 Introduced.

Code of wc_maybe_reduce_stock_levels() WC 5.3.0

<?php
function wc_maybe_reduce_stock_levels( $order_id ) {
	$order = wc_get_order( $order_id );

	if ( ! $order ) {
		return;
	}

	$stock_reduced  = $order->get_data_store()->get_stock_reduced( $order_id );
	$trigger_reduce = apply_filters( 'woocommerce_payment_complete_reduce_order_stock', ! $stock_reduced, $order_id );

	// Only continue if we're reducing stock.
	if ( ! $trigger_reduce ) {
		return;
	}

	wc_reduce_stock_levels( $order );

	// Ensure stock is marked as "reduced" in case payment complete or other stock actions are called.
	$order->get_data_store()->set_stock_reduced( $order_id, true );
}