Skip to content

Instantly share code, notes, and snippets.

@gdarko
Last active February 13, 2023 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdarko/a405df6722f064218879ad81cd049c84 to your computer and use it in GitHub Desktop.
Save gdarko/a405df6722f064218879ad81cd049c84 to your computer and use it in GitHub Desktop.
Add order id to the Vimeo title field on a GravityForms / WPForms based forms in the WooCommerce's order-received page
<?php
/**
* [WPForms]
* Prepopulate the order id in the WPForms on the order thank you page.
*
* @param $value
* @param $field
* @param $form
*
* @return string
*/
function dgv_wpforms_woocommerce_order_thankyou_page_order_id( $value, $field, $form ) {
if ( ! is_order_received_page() ) {
return $value;
}
global $wp;
$order_id = absint( $wp->query_vars['order-received'] );
$value = sprintf( 'Order ID: %s', $order_id );
return $value;
}
add_filter( 'dgv_wpforms_title_value', 'dgv_wpforms_woocommerce_order_thankyou_page_order_id', 10, 3 );
/**
* [GravityForms]
* Prepopulate the order id in the GravityForms on the order thank you page.
*
* @param $value
* @param $field
* @param $form
* @param $is_form_editor
* @param $is_entry_detail
*
* @return string
*/
function dgv_woocommerce_order_thankyou_page_order_id( $value, $field, $form, $is_form_editor, $is_entry_detail ) {
if ( $is_form_editor || $is_entry_detail ) {
return $value;
}
if ( ! is_order_received_page() ) {
return $value;
}
global $wp;
$order_id = absint( $wp->query_vars['order-received'] );
$value = sprintf( 'Order ID: %s', $order_id );
return $value;
}
add_filter( 'dgv_gf_title_value', 'dgv_woocommerce_order_thankyou_page_order_id', 10, 5 );
@ogdesigns
Copy link

Hello @gdarko Can you please explain what this code does? and could you point me in the direction on what is to be done before the inserting the code on my website.

@gdarko
Copy link
Author

gdarko commented Feb 13, 2023

Hey @ogdesigns ,

If you are using WPForms then copy the following and paste it in your theme's functions.php

/**
 * [WPForms]
 * Prepopulate the order id in the WPForms on the order thank you page.
 *
 * @param $value
 * @param $field
 * @param $form
 *
 * @return string
 */
function dgv_wpforms_woocommerce_order_thankyou_page_order_id( $value, $field, $form ) {
	if ( ! is_order_received_page() ) {
		return $value;
	}
	global $wp;
	$order_id = absint( $wp->query_vars['order-received'] );
	$value    = sprintf( 'Order ID: %s', $order_id );

	return $value;
}
add_filter( 'dgv_wpforms_title_value', 'dgv_wpforms_woocommerce_order_thankyou_page_order_id', 10, 3 );

If you are using GravityForms then copy the following and paste it in your theme's functions.php

/**
 * [GravityForms]
 * Prepopulate the order id in the GravityForms on the order thank you page.
 *
 * @param $value
 * @param $field
 * @param $form
 * @param $is_form_editor
 * @param $is_entry_detail
 *
 * @return string
 */
function dgv_woocommerce_order_thankyou_page_order_id( $value, $field, $form, $is_form_editor, $is_entry_detail ) {
	if ( $is_form_editor || $is_entry_detail ) {
		return $value;
	}
	if ( ! is_order_received_page() ) {
		return $value;
	}
	global $wp;
	$order_id = absint( $wp->query_vars['order-received'] );
	$value    = sprintf( 'Order ID: %s', $order_id );

	return $value;
}
add_filter( 'dgv_gf_title_value', 'dgv_woocommerce_order_thankyou_page_order_id', 10, 5 );

This code will print Order ID: {the order number} in the /order-received page's WPForm/GravityForm that uses Video Uploads for Vimeo PRO. Please note that you will need to embed the form through "Edit" page on the Order received page first.

Best Regards,
Darko

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment