Skip Navigation

[Résolu] Code works on dashboard but not in a CRED form

This support ticket is created Il y a 3 années et 7 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par PaulS4783 Il y a 3 années et 7 mois.

Assisté par: Luo Yang.

Auteur
Publications
#2026953

I've tried substituting "cred_submit_complete" for "wp_insert_post" but it keeps throwing a critical error.

/**
  * Description: Sets the invoice number the first time an auction vehicle is saved based on what the previous highest invoice number and incrementing by "1".
 */

// only create invoice number if the post in new, NOT an update
function set_invoice_number( $post_id, $post, $update ) {
	if ( wp_is_post_revision( $post_id ) ) {
        return;
	}

	if ( 'auction-vehicle' == $post->post_type ) {
		if( !$update ){
            $args = array(  
                'post_type' => 'auction-vehicle',
            );
            $myloop = new WP_Query( $args );
            
            //loop through all posts of this post type to find the highest invoice number
            $find_highest_id = 0;
            while ( $myloop->have_posts() ) : $myloop->the_post();
                $this_post_id = get_the_ID();
                $invoice_number = get_post_meta( $this_post_id, 'wpcf-invoice-number', true );
                if($invoice_number > $find_highest_id){
                    $find_highest_id = $invoice_number;
                }
            endwhile;
            wp_reset_postdata();
            
            //take the highest value and increment it then save as client id for the new client
            $invoice_number = $find_highest_id + 1;
            update_post_meta( $post_id, 'wpcf-invoice-number', $invoice_number);
        }
	}
}
add_action( 'wp_insert_post', 'set_invoice_number', 10, 3 );
#2027075

Hello,

When you get the "critical error" message, that means there are some PHP error in your website, please follow our document to get the PHP debug logs:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/#php-debugging

Then fix your custom PHP codes.

#2029235

I took a different approach.
You can close this ticket.