Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Last active February 7, 2020 14:57
Show Gist options
  • Save remcotolsma/4fedc10eb7eff8ecb5a924b9f288749e to your computer and use it in GitHub Desktop.
Save remcotolsma/4fedc10eb7eff8ecb5a924b9f288749e to your computer and use it in GitHub Desktop.
Pronamic Pay Google Analytics ecommerce tracking item hit name Gravity Forms entry source URL (HelpScout ticket #19062)
<?php
/**
* Custom.
*/
\add_action(
'plugins_loaded',
function() {
/**
* Check for Gravity Forms API.
*
* @link https://docs.gravityforms.com/api-functions/#get-entry
* @link https://docs.gravityforms.com/entry-object/
*/
if ( ! \method_exists( '\GFAPI', 'get_entry' ) ) {
return;
}
if ( ! \function_exists( '\rgar' ) ) {
return;
}
if ( ! \function_exists( '\pronamic_pay_plugin' ) ) {
return;
}
/**
* Filters the Google Analytics ecommerce tracking item hit name.
*/
\add_filter(
'pronamic_pay_google_analytics_ecommerce_item_name',
function( $name, $payment_line ) {
$payment = $payment_line->get_payment();
if ( null === $payment ) {
return $name;
}
$source = $payment->get_source();
if ( 'gravityformsideal' !== $source ) {
return $name;
}
$source_id = $payment->get_source_id();
$entry = \GFAPI::get_entry( $source_id );
if ( $entry instanceof \WP_Error ) {
return $name;
}
$name = \rgar( $entry, 'source_url' );
return $name;
},
10,
2
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment