WordPress at Your Fingertips
function is not described

WC_Product::validate_props() public WC 3.0.0

Ensure properties are set correctly before save.

{} It's a method of the class: WC_Product{}

No Hooks.

Return

null. Nothing.

Usage

$WC_Product = new WC_Product();
$WC_Product->validate_props();

Changelog

Since 3.0.0 Introduced.

Code of WC_Product::validate_props() WC 5.5.2

<?php
public function validate_props() {
	// Before updating, ensure stock props are all aligned. Qty, backorders and low stock amount are not needed if not stock managed.
	if ( ! $this->get_manage_stock() ) {
		$this->set_stock_quantity( '' );
		$this->set_backorders( 'no' );
		$this->set_low_stock_amount( '' );
		return;
	}

	$stock_is_above_notification_threshold = ( $this->get_stock_quantity() > get_option( 'woocommerce_notify_no_stock_amount', 0 ) );
	$backorders_are_allowed                = ( 'no' !== $this->get_backorders() );

	if ( $stock_is_above_notification_threshold ) {
		$new_stock_status = 'instock';
	} elseif ( $backorders_are_allowed ) {
		$new_stock_status = 'onbackorder';
	} else {
		$new_stock_status = 'outofstock';
	}

	$this->set_stock_status( $new_stock_status );
}