Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Ultimate › Custom Fields Stopped Working
- This topic has 3 replies, 2 voices, and was last updated 4 years, 7 months ago by Sushobhan.
- AuthorPosts
- April 11, 2020 at 12:42 am #117798SSCParticipant
Hello, I have some custom fields on my checkout page.
They suddenly stopped working and I can not figure out why. I have spent all day trying to figure this out. There are no errors in the logs.
The fields are no longer saving as post_meta.add_action('woocommerce_before_checkout_form', 'add_custom_checkout_select_field2'); function add_custom_checkout_select_field2( $checkout ) { global $woocommerce, $post ; foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) { $product = $values['data']; echo '<div id="customise_checkout_field">'; woocommerce_form_field('test_field', array( 'type' => 'text', 'class' => array( 'player-name form-row-wide' ), 'label' => __('test_field') , 'placeholder' => __('test_field') , ), $checkout->get_value('test_field')); echo '</div>'; } } add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta2' ); function my_custom_checkout_field_update_order_meta2( $order_id ) { if ( !empty( $_POST['test_field'] )) { update_post_meta( $order_id, 'test_field', sanitize_text_field( $_POST['test_field'] ) ); } } add_filter( 'woocommerce_order_details_after_order_table' , 'my_custom_checkout_field_display_admin_order_meta2', 20, 1 ); // Front add_filter( 'woocommerce_email_order_details' , 'my_custom_checkout_field_display_admin_order_meta2', 20, 1 ); // Front //Admin add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta2', 10, 1 ); function my_custom_checkout_field_display_admin_order_meta2($order){ $test_field = get_post_meta( $order->get_id(), 'test_field', true ); if ( $test_field ) { echo '<p><strong>'.__('test_field').':</strong> ' . get_post_meta( $order->get_id(), 'test_field', true ) . '</p>'; } }
- April 18, 2020 at 2:07 pm #120276SushobhanKeymaster
Hi,
What you want to achieve with this snippet? Your wrote “They suddenly stopped working”, how was it working before? Did you change anything or update plugin/WP version?
The snippet doesn’t seem right to me. Please tell me in detail what is your actual requirement. Then only, I might be able to help you out.
Thanks! - April 18, 2020 at 3:46 pm #120289SSCParticipant
I also mentioned, “The fields are no longer saving as post_meta”.
I suppose I should have added more info, it has been quite hectic over here and it was very late when I posted this xD.
I believe it stopped working after the latest update. I got back around to this today and figure out what the issue was.
Changed “woocommerce_before_checkout_form” to “woocommerce_checkout_before_customer_details” and added “$checkout = WC()->checkout();” everything works fine now, and I will no longer need help on this issue. - April 18, 2020 at 3:50 pm #120291SushobhanKeymaster
Glad you figure it out 🙂
- AuthorPosts
- You must be logged in to reply to this topic.