From 7a3552c3f9d15714a934e23676f64a7bcf99bfd9 Mon Sep 17 00:00:00 2001 From: Kim Coleman Date: Fri, 19 Jul 2024 11:13:41 -0400 Subject: [PATCH] Logic to support admin refunds. --- includes/admin.php | 159 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/includes/admin.php b/includes/admin.php index aae64c9..576cfe4 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -113,6 +113,165 @@ function pmproga4_show_setup_notice() { } add_action( 'admin_notices', 'pmproga4_show_setup_notice' ); +/** + * Load the Google Analytics script on the admin pages. + * + * @since TBD + */ +function pmproga4_load_admin_script() { + + // Only run this if PMPro is installed. + if ( ! defined( 'PMPRO_VERSION' ) ) { + return; + } + + // Only show on PMPro admin pages. + if ( empty( $_REQUEST['page'] ) || strpos( $_REQUEST['page'], 'pmpro' ) === false ) { + return; + } + + extract( $pmproga4_settings = get_option( 'pmproga4_settings', + array( + 'measurement_id' => '', + 'track_levels' => array() + ) + ) ); + + /** + * Determines whether to halt tracking based on specific conditions. + * + * This filter provides an opportunity for developers to stop tracking for specific + * scenarios, such as based on user ID, post, custom roles, etc. If the filter returns + * `true`, tracking will be halted. + * + * @since 1.0 + * + * @param bool $stop_tracking Default value is `false`. If set to `true` by any filter, tracking will be halted. + * + * @return void + */ + if ( apply_filters( 'pmproga4_dont_track', false ) ) { + return; + } + + // No measurement ID found, let's bail. + if ( empty( $measurement_id ) ) { + return; + } + + /** + * Filters the attributes applied to the Google Analytics script tag loaded in wp_admin. + * + * Allows developers to customize or add specific attributes to the Google Analytics script tag + * for enhanced control or additional features. + * + * @since 1.0 + * + * @param string $script_atts Default value is an empty string. Contains attributes for the GA script tag. + * + * @return string Modified attributes for the GA admin script tag. + */ + $script_atts = apply_filters( 'pmproga4_admin_script_atts', '' ); + + ?> + + + + id ) ) { + $pmpro_invoice->getMembershipLevel(); + + // Set the ecommerce dataLayer script. + $gtag_config_ecommerce_data = array(); + $gtag_config_ecommerce_data['transaction_id'] = $pmpro_invoice->code; + $gtag_config_ecommerce_data['value'] = $pmpro_invoice->membership_level->initial_payment; + + if ( ! empty( $pmpro_invoice->tax ) ) { + $gtag_config_ecommerce_data['tax'] = $pmpro_invoice->tax; + } else { + $gtag_config_ecommerce_data['tax'] = 0; + } + + if ( $pmpro_invoice->getDiscountCode() ) { + $gtag_config_ecommerce_data['coupon'] = $pmpro_invoice->discount_code->code; + } else { + $gtag_config_ecommerce_data['coupon'] = ''; + } + + // Build an array of product data. + $gtag_config_ecommerce_products = array(); + $gtag_config_ecommerce_products['item_id'] = $pmpro_invoice->membership_level->id; + $gtag_config_ecommerce_products['item_name'] = $pmpro_invoice->membership_level->name; + $gtag_config_ecommerce_products['affiliation'] = get_bloginfo( 'name' ); + if ( $pmpro_invoice->getDiscountCode() ) { + $gtag_config_ecommerce_products['coupon'] = $pmpro_invoice->discount_code->code; + } + $gtag_config_ecommerce_products['index'] = 0; + $gtag_config_ecommerce_products['price'] = $pmpro_invoice->membership_level->initial_payment; + $gtag_config_ecommerce_products['quantity'] = 1; + ?> + +