public/wordpress/wp-content/plugins/wp-courseware/includes/controllers/cart.php
/**
	 * Apply Coupon.
	 *
	 * @since 4.5.0
	 *
	 * @param string $coupon_code The coupon code.
	 *
	 * @return bool True if the coupon is applied, false if it does not exist or cannot be applied.
	 */
Apply Coupon.

@param string $coupon_code The coupon code.

@return bool True if the coupon is applied, false if it does not exist or cannot be applied.
Apply Coupon . @param string $coupon_code The coupon code . @return bool True if the coupon is applied false if it does not exist or cannot be applied .
public function apply_coupon( $coupon_code ) {
		if ( ! wpcw_coupons_enabled() ) {
			return false;
		}
		$coupon_code = wpcw_format_coupon_code( $coupon_code );
		$coupon = wpcw_get_coupon_by_code( $coupon_code );
		if ( $coupon->get_code() !== $coupon_code ) {
			$coupon->set_prop( 'code', $coupon_code );
			$coupon->add_coupon_error( Coupon::E_COUPON_NOT_EXIST );
			return false;
		}
		if ( ! $coupon->is_valid() ) {
			return false;
		}
		if ( $this->has_coupon_been_applied( $coupon_code ) ) {
			$coupon->add_coupon_error( Coupon::E_COUPON_ALREADY_APPLIED );
			return false;
		}
		if ( $coupon->get_individual_use() ) {
			$coupons_to_keep = apply_filters( 'wpcw_apply_individual_use_coupon', array(), $coupon, $this->applied_coupons );
			foreach ( $this->applied_coupons as $applied_coupon ) {
				$keep_key = array_search( $applied_coupon, $coupons_to_keep, true );
				if ( false === $keep_key ) {
					$this->remove_coupon( $applied_coupon );
				} else {
					unset( $coupons_to_keep[ $keep_key ] );
				}
			}
			if ( ! empty( $coupons_to_keep ) ) {
				$this->applied_coupons += $coupons_to_keep;
			}
		}
		if ( $this->applied_coupons ) {
			foreach ( $this->applied_coupons as $code ) {
				$iu_coupon = wpcw_get_coupon_by_code( $code );
				$apply_with_iu_coupon = apply_filters( 'wpcw_apply_with_individual_use_coupon', false, $coupon, $iu_coupon, $this->applied_coupons );
				if ( $iu_coupon->get_individual_use() && false === $apply_with_iu_coupon ) {
					$iu_coupon->add_coupon_error( Coupon::E_COUPON_ALREADY_APPLIED_INDIV_USE_ONLY );
					return false;
				}
			}
		}
		$this->applied_coupons[] = $coupon_code;
		$coupon->add_coupon_message( Coupon::M_COUPON_SUCCESS );
		$this->update_applied_coupons();
		do_action( 'wpcw_applied_coupon', $coupon_code, $coupon, $this );
		return true;
	}
public function apply_coupon ( $ coupon_code ) { if ( ! wpcw_coupons_enabled ( ) ) { return false ; } $ coupon_code = wpcw_format_coupon_code ( $ coupon_code ) ; $ coupon = wpcw_get_coupon_by_code ( $ coupon_code ) ; if ( $ coupon -> get_code ( ) !== $ coupon_code ) { $ coupon -> set_prop ( 'code' , $ coupon_code ) ; $ coupon -> add_coupon_error ( Coupon :: E_COUPON_NOT_EXIST ) ; return false ; } if ( ! $ coupon -> is_valid ( ) ) { return false ; } if ( $ this -> has_coupon_been_applied ( $ coupon_code ) ) { $ coupon -> add_coupon_error ( Coupon :: E_COUPON_ALREADY_APPLIED ) ; return false ; } if ( $ coupon -> get_individual_use ( ) ) { $ coupons_to_keep = apply_filters ( 'wpcw_apply_individual_use_coupon' , array ( ) , $ coupon , $ this -> applied_coupons ) ; foreach ( $ this -> applied_coupons as $ applied_coupon ) { $ keep_key = array_search ( $ applied_coupon , $ coupons_to_keep , true ) ; if ( false === $ keep_key ) { $ this -> remove_coupon ( $ applied_coupon ) ; } else { unset ( $ coupons_to_keep [ $ keep_key ] ) ; } } if ( ! empty ( $ coupons_to_keep ) ) { $ this -> applied_coupons += $ coupons_to_keep ; } } if ( $ this -> applied_coupons ) { foreach ( $ this -> applied_coupons as $ code ) { $ iu_coupon = wpcw_get_coupon_by_code ( $ code ) ; $ apply_with_iu_coupon = apply_filters ( 'wpcw_apply_with_individual_use_coupon' , false , $ coupon , $ iu_coupon , $ this -> applied_coupons ) ; if ( $ iu_coupon -> get_individual_use ( ) && false === $ apply_with_iu_coupon ) { $ iu_coupon -> add_coupon_error ( Coupon :: E_COUPON_ALREADY_APPLIED_INDIV_USE_ONLY ) ; return false ; } } } $ this -> applied_coupons [ ] = $ coupon_code ; $ coupon -> add_coupon_message ( Coupon :: M_COUPON_SUCCESS ) ; $ this -> update_applied_coupons ( ) ; do_action ( 'wpcw_applied_coupon' , $ coupon_code , $ coupon , $ this ) ; return true ; }
Apply Coupon.
Apply Coupon .
// Check if coupons are enabled. // Format coupon code. // Coupon. // Prevent adding coupons by Id. // Check it can be used with cart. // Check if applied. // If its individual use then remove other coupons. /**
			 * Filter: Apply Individual Use Coupon.
			 *
			 * @since 4.5.0
			 *
			 * @param string $coupon The coupon code.
			 * @param array The array of applied coupons.
			 *
			 * @return array The array of coupons to keep.
			 */ // Check to see if an individual use coupon is set. /**
				 * Filter: Apply with Individual Use Coupon.
				 *
				 * @since 4.5.0
				 *
				 * @param string $coupon The coupon code.
				 * @param string $iu_coupon The individual use coupon.
				 * @param array The array of applied coupons.
				 *
				 * @return bool True if the individual use coupon should be applied.
				 */ // Add to applied coupons. // Add Success Message. // Update Applied Coupons. /**
		 * Hook: Applied Coupon.
		 *
		 * @sicne 4.5.0
		 *
		 * @param string $coupon_code The coupon code.
		 * @param Coupon $coupon The coupon object.
		 * @param Cart   $this The cart object.
		 */