WordPress at Your Fingertips
function is not described

WC_Cart_Totals::get_coupons_from_cart() protected WC 3.2.0

Return array of coupon objects from the cart. Normalises data into the same format for use by this class.

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

Hooks from the method

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_coupons_from_cart();

Changelog

Since 3.2.0 Introduced.

Code of WC_Cart_Totals::get_coupons_from_cart() WC 5.9.0

protected function get_coupons_from_cart() {
	$this->coupons = $this->cart->get_coupons();

	foreach ( $this->coupons as $coupon ) {
		switch ( $coupon->get_discount_type() ) {
			case 'fixed_product':
				$coupon->sort = 1;
				break;
			case 'percent':
				$coupon->sort = 2;
				break;
			case 'fixed_cart':
				$coupon->sort = 3;
				break;
			default:
				$coupon->sort = 0;
				break;
		}

		// Allow plugins to override the default order.
		$coupon->sort = apply_filters( 'woocommerce_coupon_sort', $coupon->sort, $coupon );
	}

	uasort( $this->coupons, array( $this, 'sort_coupons_callback' ) );
}