Auto-populate dropdown with Order-IDs from Woocommerce
-
Hi,
I have a page for logged-in-users, where they can add a text to an order. I have already added a custom smart tag (WooOrderID) but I now need to let the user select which order to add the text to. To achieve this, I would like a dropdown, where the user can select the order by it’s order-id (say the user has three orders, the dropdown would show 700, 734, 811).
How do I auto-populate a dropdown?
Here’s the code for getting the order-ids into a smart tag (it only get’s the oldest id):
// Register wpForms SmartTag function wpf_dev_register_smarttag( $tags ) { $tags['woo_orderid'] = 'WooOrderID'; return $tags; } add_filter( 'wpforms_smart_tags', 'wpf_dev_register_smarttag' ); //Pull Woo data from UserID function wpf_dev_process_smarttag( $content, $tag ) { $userID = get_current_user_id(); if ( 'woo_orderid' === $tag ) { $order= wc_get_orders(array( 'customer_id' => $userID, 'return' => 'ids', )); foreach ($order as $ids => $oids) { $oids; } $content = str_replace( '{woo_orderid}', $oids, $content ); } return $content; } add_filter( 'wpforms_smart_tag_process', 'wpf_dev_process_smarttag', 10, 2 ); // End wpf_dev_register_smarttag function
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Auto-populate dropdown with Order-IDs from Woocommerce’ is closed to new replies.