WC_Product::is_on_sale()publicWC 1.0

Returns whether or not the product is on sale.

Метод класса: WC_Product{}

Хуки из метода

Возвращает

true|false.

Использование

$WC_Product = new WC_Product();
$WC_Product->is_on_sale( $context );
$context(строка)
What the value is for. Valid values are view and edit.
По умолчанию: 'view'

Код WC_Product::is_on_sale() WC 8.7.0

public function is_on_sale( $context = 'view' ) {
	if ( '' !== (string) $this->get_sale_price( $context ) && $this->get_regular_price( $context ) > $this->get_sale_price( $context ) ) {
		$on_sale = true;

		if ( $this->get_date_on_sale_from( $context ) && $this->get_date_on_sale_from( $context )->getTimestamp() > time() ) {
			$on_sale = false;
		}

		if ( $this->get_date_on_sale_to( $context ) && $this->get_date_on_sale_to( $context )->getTimestamp() < time() ) {
			$on_sale = false;
		}
	} else {
		$on_sale = false;
	}
	return 'view' === $context ? apply_filters( 'woocommerce_product_is_on_sale', $on_sale, $this ) : $on_sale;
}