Skip Navigation

[Resolved] Post status not change after order purchase

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Joan 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1180195

I have a post form were I can purchase 2 different products. Every time I go to the page of the form I can buy one product. If i buy two products these are added correctly to the cart. But the problem is that after the order is paid only change the post status of one of the products purchased.

In the settings of the post form I have the option "Set this post status:" to "draft" and at the end in the "Post status when the payment status updates":
Purchase processing:"Draft"
Purchase complete: "Published"
Purchase refunded: "Move to trash"
Purchase cancelled: "Move to trash"

After payment one product change his status to "published" but the other has the status of "draft"

Is there something to do?

Thanks.

#1180251

I have a post form were I can purchase 2 different products.
Hi, can you tell me more about how you set this up? Please share any code from the Form editor here for me to review. If you have used any custom PHP code with the Forms Commerce API, please share that code here as well.

After payment one product change his status to "published" but the other has the status of "draft"
Are you trying to change the status of the Product that was purchased, or of the post created/edited by Forms? What type of post is being created or edited by this Form?

The settings in Forms Commerce are used to change the status of the post that was created or edited by Forms, not the Product that was purchased.

#1180280

I have a post form were I can purchase 2 different products.
Hi, can you tell me more about how you set this up? Please share any code from the Form editor here for me to review. If you have used any custom PHP code with the Forms Commerce API, please share that code here as well

The form is for create a Custom Post Type. There is a field where you can choose the product to buy by "The form specifies the product according to the value of this custom field: " "field 1".

The fields of the form are numerical or text field except the field where you can select the product that is

 <div class="form-group">
		<label>Field 1</label>
    [cred_field field='field1' post='CPT1' value='' urlparam='' select_text='--- not set ---' class='form-control' output='bootstrap']
	</div>

This form have some custom code related to the hooks "cred_form_validate" and "cred_save_data" but not related to the Forms Commerce API.

I show the code:


add_action('cred_save_data', 'save_first_CPT1',10,2);
function save_first_CPT1($post_id, $form_data){
if($form_data['id']==1248){

		//Get CPT1 data
        $n_CPT1=get_the_title( $post_id);
        $nu_CPT1=get_post_meta( $post_id, "wpcf_old_num-de-CPT1-ja-pagat", true );
        $met_CPT1=get_post_meta( $post_id, "wpcf-metode-de-pagament-CPT1", true );


        //Si CPT1 exsitent
        	
   		if($met_CPT1==74){

   			if(isset($$nu_CPT1)){

				$id_CPT1_vell_a_eli=0;
	  			//Buscar id post antic
	  			// The Query
	  			$argum = array('post_type' => 'CPT1-antic');
				$consult = new WP_Query( $argum );
				// The Loop
				if ( $consult->have_posts() ) {
	  				while ( $consult->have_posts() ) {
	    				$consult->the_post();
		    			$CPT1_ide=get_the_ID();
		    			$date_CPT1=get_post_meta( $CPT1_ide,'wpcf_old_naix',true );
		    			$old_num_CPT1=get_post_meta( $CPT1_ide,'wpcf_old_num-CPT1-antic',true );
		    			$old_name_CPT1=get_the_title();
		         
		    			if(((strcmp($n_CPT1, $old_name_CPT1))==0)&&($old_num_CPT1==$$nu_CPT1)){
		    				$id_CPT1_vell_a_eli=$CPT1_ide;
			    		}
		    	}
		    	/* Restore original Post Data */
				wp_reset_postdata();
		    			
				} else {
					echo "NO posts";
				}
		    				
		  		
				//Delete post CPT1 antic
	    	
				if($id_CPT1_vell_a_eli!=0){	
				wp_trash_post($id_CPT1_vell_a_eli);	  			
			  	}
			  }

    		}else{

    			if($met_CPT1==32){
    				//Assignar num CPT1
    				//Buscar el número CPT1 antic més alt

    				$argume = array('post_type' => 'CPT1-antic');
					$conslt = new WP_Query( $argume );
					// The Loop
					$old_num_CPT1_temp=0;
					$old_num_CPT1_max=0;
					if ( $conslt->have_posts() ) {
	  					while ( $conslt->have_posts() ) {
	    				$conslt->the_post();
	    				$CPT1_iden=get_the_ID();
	    				$old_num_CPT1_temp=get_post_meta( $CPT1_iden,'wpcf_old_num-CPT1-antic',true );
	    			
	    				if($old_num_CPT1_temp>$old_num_CPT1_max){
	    					$old_num_CPT1_max=$old_num_CPT1_temp;
	    				}    
	    			
	    			}
	    			/* Restore original Post Data */
					wp_reset_postdata();
	    			
					} else {
						echo "No CPT1s old";
					}
    			
					//Recorrer el número de CPT1 existent més alt

					$argume = array('post_type' => 'CPT1cdp');
					$conslt = new WP_Query( $argume );
					// The Loop
					$num_cpt1_nou_temp=0;
					$num_cpt1_nou_max=0;
					if ( $conslt->have_posts() ) {
	  					while ( $conslt->have_posts() ) {
	    					$conslt->the_post();
	    					$CPT1_ident=get_the_ID();
	    					$num_cpt1_nou_temp=get_post_meta( $CPT1_ident,'wpcf_old_num-de-CPT1-ja-pagat',true );
	    			
	    					if($num_cpt1_nou_temp>$num_cpt1_nou_max){
	    					$num_cpt1_nou_max=$num_cpt1_nou_temp;
	    					}
	    			
	    				}
	    			/* Restore original Post Data */
					wp_reset_postdata();
	    			
					} else {
						echo "No CPT1s news";
					}

					if($num_cpt1_nou_max>$old_num_CPT1_max){
						$num_cpt1_sav=$num_cpt1_nou_max+1;
					}	
					else{
						echo "something wrong";
						$num_cpt1_sav=999999999999;

					}




    			}	
      		}
    			

      		//Save CPT1 
	       	$elmeur_post = array(
      		'ID' => $post_id,
      		'post_title' =>$n_CPT1);

        	if(isset($post_id,$n_CPT1)){
      			wp_update_post( $elmeur_post);
      		}

      		if (is_wp_error($post_id)) {
      			$errors = $post_id->get_error_messages();
      			foreach ($errors as $error) {
      				echo $error;
      			}
      		}

      		if(isset($num_cpt1_sav)){
      		update_post_meta($post_id, 'wpcf_old_num-de-CPT1-ja-pagat', $num_cpt1_sav);
      		}

			
		  	
    }		
    	
}

After payment one product change his status to "published" but the other has the status of "draft"
Are you trying to change the status of the Product that was purchased, or of the post created/edited by Forms? What type of post is being created or edited by this Form?
I'm trying to change the status of the post created by the form. I hope that the status change to "published" when the order related to products added to the cart in this form change to "completed".

Thanks

#1180318

I think I understand now. You have a Commerce Form on the site, and your visitors submit the Form multiple times before checking out. This adds multiple products to the cart and creates multiple posts. Then after creating multiple posts the visitor "checks out", with multiple products in the cart. Is this correct? If so, I'm afraid Commerce Forms do not support multiple products in a single Order. You must use the option "Clear the cart and include only the selected product", and only allow one product per Order. Otherwise, the notifications and post update systems built into Forms Commerce will not function as expected.

Let me know if I have misunderstood your request.

#1180770

Ok, you understand well.

I understand this but I don't understand what is the sense of the option "Leave the cart content and add the selected product" if it doesn't work after the cart is paid. I think that this could be a good improvement for the plugin.

Thanks.