Skip to content

Commit

Permalink
Fix #153
Browse files Browse the repository at this point in the history
Deactivation survey v1 to v2... tracking survey v1 to v2 Fix #153
  • Loading branch information
mital-tyche committed Nov 7, 2023
1 parent 87274a2 commit 864064f
Show file tree
Hide file tree
Showing 8 changed files with 815 additions and 35 deletions.
74 changes: 66 additions & 8 deletions checkout-fees-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public function __construct() {
add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_woocommerce_settings_tab' ) );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) );
add_action( 'before_woocommerce_init', array( &$this, 'pgbf_lite_custom_order_tables_compatibility' ), 999 );
add_action( 'admin_footer', array( $this, 'ts_admin_notices_scripts' ) );
add_action( 'admin_init', array( $this, 'ts_reset_tracking_setting' ) );
add_action( 'pgbf_lite_init_tracker_completed', array( $this, 'init_tracker_completed' ), 10, 2 );
add_filter( 'ts_tracker_data', array( 'Cf_Tracking_Functions', 'cf_plugin_tracking_data' ), 10, 1 );
// Admin core.
require_once 'includes/class-alg-wc-checkout-fees-admin.php';
// Settings.
Expand Down Expand Up @@ -171,19 +175,73 @@ public function includes() {
$this->core = require_once 'includes/class-alg-wc-checkout-fees.php';
$pgbf_plugin_url = plugins_url() . '/checkout-fees-for-woocommerce';
require_once 'includes/class-alg-wc-order-fees.php';
// plugin deactivation.
require_once 'includes/class-tyche-plugin-deactivation.php';
new Tyche_Plugin_Deactivation(

// Data Tracking.
include_once 'includes/class-cf-tracking-functions.php';
include_once 'includes/class-alg-wc-all-component.php';
}


/**
* Added tracking dismiss notice js.
*/
public static function ts_admin_notices_scripts() {
wp_enqueue_script(
'pgbf_lite_ts_dismiss_notice',
plugins_url() . '/checkout-fees-for-woocommerce/includes/js/tyche-dismiss-tracking-notice.js',
'',
'',
false
);

wp_localize_script(
'pgbf_lite_ts_dismiss_notice',
'pgbf_lite_ts_dismiss_notice',
array(
'plugin_name' => 'Payment Gateway Based Fees and Discounts for WooCommerce',
'plugin_base' => 'checkout-fees-for-woocommerce/checkout-fees-for-woocommerce.php',
'script_file' => $pgbf_plugin_url . '/includes/js/plugin-deactivation.js',
'plugin_short_name' => 'pgbf_lite',
'version' => $this->version,
'ts_prefix_of_plugin' => 'pgbf_lite',
'ts_admin_url' => admin_url( 'admin-ajax.php' ),
)
);
}


/**
* This function includes js files required for admin side.
*
* @hook admin_enqueue_scripts
*
* @since 2.9.0
*/
function enqueue_script() {
wp_register_script(
'tyche',
plugins_url() . '/checkout-fees-for-woocommerce/includes/js/tyche.js',
array( 'jquery' ),
$this->version,
true
);
wp_enqueue_script( 'tyche' );
}

/**
* Remove query string to the admin url.
*/
public static function ts_reset_tracking_setting() {
if ( isset( $_GET ['ts_action'] ) && 'reset_tracking' == $_GET ['ts_action'] ) {
Tyche_Plugin_Tracking::reset_tracker_setting( 'pgbf_lite' );
$ts_url = remove_query_arg( 'ts_action' );
wp_safe_redirect( $ts_url );
}
}

/**
* Redirect page after tracking completed.
*/
public static function init_tracker_completed() {
header( 'Location: ' . admin_url( 'admin.php?page=wc-settings&tab=alg_checkout_fees' ) );
exit;
}

/**
* Add translations as per user language.
*
Expand Down
95 changes: 95 additions & 0 deletions includes/class-alg-wc-all-component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* Checkout Fees for WooCommerce
*
* @author Tyche Softwares
*
* @package checkout-fees-for-woocommerce-pro/checkout
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'Alg_WC_All_Component' ) ) {
/**
* It will Add all the Boilerplate component when we activate the plugin.
*
*/
class Alg_WC_All_Component {

/**
* It will Add all the Boilerplate component when we activate the plugin.
*/
public function __construct() {

$is_admin = is_admin();

if ( true === $is_admin ) {

$pgbf_plugin_name = self::ts_get_plugin_name();;
$pgbf_locale = self::ts_get_plugin_locale();
$plugin_url = plugins_url() . '/checkout-fees-for-woocommerce';
$pgbf_file_name = 'checkout-fees-for-woocommerce/checkout-fees-for-woocommerce.php';
$pgbf_plugin_prefix = 'pgbf_lite';

$pgbf_blog_post_link = 'https://www.tychesoftwares.com/docs/docs/payment-gateway-based-fees-and-discounts-for-woocommerce/payment-gateway-based-fees-and-discounts-usage-tracking/';
$pgbf_get_previous_version = get_option( 'alg_woocommerce_checkout_fees_version' );

require_once( "component/plugin-deactivation/class-tyche-plugin-deactivation.php" );
new Tyche_Plugin_Deactivation(
array(
'plugin_name' => $pgbf_plugin_name,
'plugin_base' => $pgbf_file_name,
'script_file' => $plugin_url . '/includes/js/plugin-deactivation.js',
'plugin_short_name' => $pgbf_plugin_prefix,
'version' => $pgbf_get_previous_version,
'plugin_locale' => $pgbf_locale,
)
);

require_once( "component/plugin-tracking/class-tyche-plugin-tracking.php" );
new Tyche_Plugin_Tracking(
array(
'plugin_name' => $pgbf_plugin_name,
'plugin_locale' => $pgbf_locale,
'plugin_short_name' => $pgbf_plugin_prefix,
'version' => $pgbf_get_previous_version,
'blog_link' => $pgbf_blog_post_link,
)
);
}
}

/**
* It will retrun the plguin name.
* @return string $ts_plugin_name Name of the plugin
*/
public static function ts_get_plugin_name () {
$pgbf_plugin_dir = dirname ( dirname ( __FILE__ ) );
$pgbf_plugin_dir .= '/checkout-fees-for-woocommerce.php';

$ts_plugin_name = '';
$plugin_data = get_file_data( $pgbf_plugin_dir, array( 'name' => 'Plugin Name' ) );
if ( ! empty( $plugin_data['name'] ) ) {
$ts_plugin_name = $plugin_data[ 'name' ];
}
return $ts_plugin_name;
}

/**
* It will retrun the Plugin text Domain
* @return string $ts_plugin_domain Name of the Plugin domain
*/
public static function ts_get_plugin_locale () {
$pgbf_plugin_dir = dirname ( dirname ( __FILE__ ) );
$pgbf_plugin_dir .= '/checkout-fees-for-woocommerce.php';

$ts_plugin_domain = '';
$plugin_data = get_file_data( $pgbf_plugin_dir, array( 'domain' => 'Text Domain' ) );
if ( ! empty( $plugin_data['domain'] ) ) {
$ts_plugin_domain = $plugin_data[ 'domain' ];
}
return $ts_plugin_domain;
}
}
$Alg_WC_All_Component = new Alg_WC_All_Component();
}
159 changes: 159 additions & 0 deletions includes/class-cf-tracking-functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php
/**
* Payment Gateway Based Fees and Discounts for WooCommerce - Data Tracking Functions
*
* @version 2.6.3
* @since 2.6.3
* @package Payment Gateway Based Fees and Discounts/Data Tracking
* @author Tyche Softwares
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

if ( ! class_exists( 'Cf_Tracking_Functions' ) ) :

/**
* Payment Gateway Based Fees and Discounts for WooCommerce Tracking Functions.
*/
class Cf_Tracking_Functions {

/**
* Construct.
*
* @since 2.6.3
*/
public function __construct() {

}

/**
* Returns plugin data for tracking.
*
* @param array $data - Generic data related to WP, WC, Theme, Server and so on.
* @return array $data - Plugin data included in the original data received.
* @since 2.6.3
*/
public static function cf_plugin_tracking_data( $data ) {

$plugin_data = array(
'ts_meta_data_table_name' => 'ts_tracking_pgbf_pro_meta_data',
'ts_plugin_name' => 'Payment Gateway Based Fees and Discounts for WooCommerce',
'global_settings' => self::cf_get_global_settings(),
'enabled_payment_gateways' => self::cf_get_enabled_payment_gateways(),
);

$active_gateways = self::wc_payment_gateways();
foreach ( $active_gateways as $key => $value ) {
$args = alg_wc_cf()->core->args_manager->get_the_args_global( $key );
$plugin_data[ $key . 'settings' ] = $args;
}

$active_gateways = WC()->payment_gateways->payment_gateways();
foreach ( $active_gateways as $gateway => $gateway_data ) {
$count = self::cf_get_gateway_based_product_counts( $gateway );
$plugin_data[ $gateway . '_product_count' ] = $count;
}

$data['plugin_data'] = $plugin_data;
return $data;
}

/**
* Send the global settings for tracking.
* Settings from the Genetral, Behavior & Advanced tabs are captured here.
*
* @since 2.6.3
*/
public static function cf_get_global_settings() {

$global_settings = array(
'alg_woocommerce_checkout_fees_enabled' => get_option( 'alg_woocommerce_checkout_fees_enabled' ),
'alg_woocommerce_checkout_fees_per_product_enabled' => get_option( 'alg_woocommerce_checkout_fees_per_product_enabled' ),
'alg_woocommerce_checkout_fees_per_product_add_product_name' => get_option( 'alg_woocommerce_checkout_fees_per_product_add_product_name' ),
'alg_woocommerce_checkout_fees_merge_all_fees' => get_option( 'alg_woocommerce_checkout_fees_merge_all_fees' ),
'alg_woocommerce_checkout_fees_range_max_total_discounts' => get_option( 'alg_woocommerce_checkout_fees_range_max_total_discounts' ),
'alg_woocommerce_checkout_fees_range_max_total_fees' => get_option( 'alg_woocommerce_checkout_fees_range_max_total_fees' ),
'alg_woocommerce_checkout_fees_hide_on_cart' => get_option( 'alg_woocommerce_checkout_fees_hide_on_cart' ),
'alg_woocommerce_checkout_fees_info_enabled' => get_option( 'alg_woocommerce_checkout_fees_info_enabled' ),
'alg_woocommerce_checkout_fees_info_start_template' => get_option( 'alg_woocommerce_checkout_fees_info_start_template' ),
'alg_woocommerce_checkout_fees_info_row_template' => get_option( 'alg_woocommerce_checkout_fees_info_row_template' ),
'alg_woocommerce_checkout_fees_info_end_template' => get_option( 'alg_woocommerce_checkout_fees_info_end_template' ),
'alg_woocommerce_checkout_fees_info_hook' => get_option( 'alg_woocommerce_checkout_fees_info_hook' ),
'alg_woocommerce_checkout_fees_info_hook_priority' => get_option( 'alg_woocommerce_checkout_fees_info_hook_priority' ),
'alg_woocommerce_checkout_fees_lowest_price_info_enabled' => get_option( 'alg_woocommerce_checkout_fees_lowest_price_info_enabled' ),
'alg_woocommerce_checkout_fees_lowest_price_info_template' => get_option( 'alg_woocommerce_checkout_fees_lowest_price_info_template' ),
'alg_woocommerce_checkout_fees_lowest_price_info_hook' => get_option( 'alg_woocommerce_checkout_fees_lowest_price_info_hook' ),
'alg_woocommerce_checkout_fees_lowest_price_info_hook_priority' => get_option( 'alg_woocommerce_checkout_fees_lowest_price_info_hook_priority' ),
'alg_woocommerce_checkout_fees_variable_info' => get_option( 'alg_woocommerce_checkout_fees_variable_info' ),
'alg_woocommerce_checkout_fees_global_fee_enabled' => get_option( 'alg_woocommerce_checkout_fees_global_fee_enabled' ),
'alg_woocommerce_checkout_fees_global_fee_as_extra_enabled' => get_option( 'alg_woocommerce_checkout_fees_global_fee_as_extra_enabled' ),
'alg_woocommerce_checkout_fees_global_fee_gateways_excl' => get_option( 'alg_woocommerce_checkout_fees_global_fee_gateways_excl' ),
'alg_woocommerce_checkout_fees_global_fee_title' => get_option( 'alg_woocommerce_checkout_fees_global_fee_title' ),
'alg_woocommerce_checkout_fees_global_fee_value' => get_option( 'alg_woocommerce_checkout_fees_global_fee_value' ),
);

return $global_settings;

}

/**
* Enabled Payment Gateways Information
*
* @since 2.6.3
*/
public static function cf_get_enabled_payment_gateways() {

$active_gateways = self::wc_payment_gateways();

return $active_gateways;
}

/**
* Fetch Enabled Payment Gateways Information
*
* @since 2.6.3
*/
public static function wc_payment_gateways() {

$active_gateways = array();
$gateways = WC()->payment_gateways->payment_gateways();
foreach ( $gateways as $id => $gateway ) {
if ( isset( $gateway->enabled ) && 'yes' === $gateway->enabled ) {
$active_gateways[ $id ] = array(
'title' => $gateway->title,
'supports' => $gateway->supports,
);
}
}

return $active_gateways;
}

/**
* Returns the number of products for the given gateway.
*
* @param string $gateway - Gateway Code.
* @return int $count - Count of products.
* @since 2.6.3
*/
public static function cf_get_gateway_based_product_counts( $gateway = '' ) {

if ( '' !== $gateway ) {

$gateway = '_alg_checkout_fees_enabled_' . $gateway;

global $wpdb;
$count = $wpdb->get_var( $wpdb->prepare( "SELECT count(post_id) FROM `" . $wpdb->prefix . "postmeta` WHERE meta_key = %s AND meta_value = %s", $gateway, 'yes' ) ); // phpcs:ignore

return $count;
}

return 0;
}
}

endif;

$cf_tracking_functions = new Cf_Tracking_Functions();
Loading

0 comments on commit 864064f

Please sign in to comment.