WC_Coupon::set_discount_type_core │ private │ WC 10.3.0

Set discount type, optionally disabling the type verification.

Method of the class: WC_Coupon{}

No Hooks.

Returns

void. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->set_discount_type_core( $discount_type, $verify_discount_type );
$discount_type(string) (required)
Discount type.
$verify_discount_type(true|false) (required)
Whether to verify if the discount type is valid.

Changelog

Since 10.3.0 Introduced.

WC_Coupon::set_discount_type_core() code WC 11.1.2

private function set_discount_type_core( $discount_type, bool $verify_discount_type ) {
	if ( 'percent_product' === $discount_type ) {
		$discount_type = 'percent'; // Backwards compatibility.
	}
	if ( $verify_discount_type && ! in_array( $discount_type, array_keys( wc_get_coupon_types() ), true ) ) {
		$this->error( 'coupon_invalid_discount_type', __( 'Invalid discount type.', 'woocommerce' ) );
	}
	$this->set_prop( 'discount_type', $discount_type );
}