Could you please

Could you please help me with MarketPress coupon codes. I tried testing and after entering the coupon code at checkout an infinite loading appears.
There is the following error in debug.log
[05-Oct-2017 13:12:09 UTC] PHP Fatal error: Call to a member function format() on boolean in /wp-content/plugins/marketpress/includes/addons/mp-coupons/class-mp-coupon.php on line 468
Debug log is available in chat.

  • Dimitris

    Hello there Stefan,

    hope you're doing good today! :slight_smile:

    As I was also unable to replicate this issue in a test installation of mine, and all of your store settings seems legit, I've escalated this to our Second Level Support devs for further investigation.
    Me or another colleague of mine will keep you posted here, as soon as we have some valuable insights! :slight_smile:

    Take care,
    Dimitris

  • Ivan

    Hi Stefan !

    It seems it was a bug in the plugin. I fixed it on your site and it works fine. If you have the same issue on other sites - you can replace is_valid function (approximately 451nd line) in {wordpress_folder}/wp-content/plugins/marketpress/includes/addons/mp-coupons/class-mp-coupon.php file via FTP. Final function should be look like

    public function is_valid( $action = '' ) {
    	$now      = time();
    	$is_valid = true;
    
    	//Moved to variable as it will be used in many instances
    	$cart_products = $this->get_products( true ) ;
    
    	$coupon_start 			= get_post_meta( $this->ID, 'start_date', true );
    	$coupon_end 			= get_post_meta( $this->ID, 'end_date', true );
    
    	if ( ! $this->exists() ) {
    		$is_valid = false;
    	} elseif ( $this->remaining_uses( false, true ) == 0 ) {
    		$is_valid = false;
    	} elseif ( $now < strtotime( $coupon_start ) ) {
    		$is_valid = false;
    	} elseif ( $this->get_meta( 'has_end_date' ) && ( $now > strtotime( $coupon_end ) ) ) {
    		$is_valid = false;
    	} elseif ( array() == $cart_products) {
    		$is_valid = false;
    	}elseif( ! $this->valid_for_number_of_products( $cart_products ) ){
    		$is_valid = false;
    	}elseif( ! $this->valid_for_login() ){
    		$is_valid = false;
    	}else {
    		if( $action != 'remove_item' ) {
    			if ( $this->get_meta( 'applies_to' ) == 'user' ) {
    				$user = $this->get_meta( 'user' );
    
    				if ( !in_array( get_current_user_id(), $user ) ) {
    					$is_valid = false;
    				}
    			}
    
    			if( ! $this->is_valid_for_combination() ) {
    				$is_valid = false;
    			}
    		}
    	}
            /**
    	 * Filter is coupon is valid
    	 *
    	 * @since 3.0
    	 *
    	 * param bool Is valid?
    	 * param MP_Coupon The current coupon object.
    	 */
    
    	return apply_filters( 'mp_coupon/is_valid', $is_valid, $this );
    }

    Also, I'll ping our developer to implement this fix to the next versions of the plugin.

    Best regards,
    Ivan.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.