How to add custom parameter in Custom Thank You Page URL

One of our client – Nordin – got back to us with a request. He wanted to append a custom parameter – user’s billing first name – in the Custom Thank You Page url in the plugin Custom Thank You Pages For WooCommerce.

Custom Thank You Pages plugin comes with a filter wherein you can append any custom parameter in the URL. Here is that filter:

apply_filters( 'modify_ctp_url', $thankyou_page_url );

Following code snippet will append customer’s billing first name in your Custom Thank You Page URL:

add_filter( 'modify_ctp_url', 'my_custom_ctp_url' );
function my_custom_ctp_url( $thankyou_page_url ) {
	$part_url = parse_url( $thankyou_page_url );

	if ( isset( $part_url ) && isset( $part_url['query'] ) ) {
		$query_params = array();
		parse_str( $part_url['query'], $query_params );

		$order_id = absint( $query_params['ctp_order_id'] );
		$order = wc_get_order( $order_id );

		if ( $order instanceof WC_Order ) {
			$thankyou_page_url = add_query_arg(
							array(
								'ctp_first_name' => $order->get_billing_first_name(),
							), $thankyou_page_url
						);
		}

	}

	return $thankyou_page_url;
}

You can insert above code snippet in a custom code plugin of your site. If you don’t have a custom code plugin, you can refer this article.

« Back to Custom Thank You Page For WooCommerce