I'm using the function 'Add order ID to entry' from WooCommerce and using your PHP code. But I'm using several forms on my site and the code is only designed for one form. I have tried to dublicate the code, but it's not possible to run the same code several tims.
So, is there a way to modify the code to include several forms? If for example if I have four forms and want to include the order number to the form that's being used.
Original code:
add_action( 'woocommerce_new_order_item', 'add_order_id_to_entry', 10, 3 ); function add_order_id_to_entry( $item_id, $cart_item, $order_id ) { // check if there's form data to process if ( empty( $cart_item->legacy_values['_formidable_form_data'] ) ) { return; } // get form entry $entry = FrmEntry::getOne( $cart_item->legacy_values['_formidable_form_data'] ); if ( $entry && $entry->form_id == 25 ) { $field_id = 123; $added = FrmEntryMeta::add_entry_meta( $entry->id, $field_id, null, $order_id ); if ( ! $added ) { FrmEntryMeta::update_entry_meta( $entry->id, $field_id, null, $order_id ); } } }
First of all, allow me to clear up a misconception about "using your PHP code". This is a community forum where questions are answered by volunteers. We are end users just like you. There is no code provides by Strategy 11 that can be called "our" code. We have no affiliation with Strategy 11 or any of the products they produce. Change this line "$entry && $entry->form_id == 25" to "$entry && in_array($entry->form_id, array("25", "26", "27")". This will allow you to add as many forms as you want to validate.
One way is to create an array of acceptable form IDs and then in the "if ($entry..." statement change the == to an in_array call and the inside the if use a switch statement to set the $field_id to the correct field id based on the value of $entry->form_id. NOTE: This is a PHP coding issue, not specifically a Formidable issue. If you need help with custom coding you can reach out to a developer- https://formidable-masterminds.com/developers-directory/
Please login or Register to submit your answer