Merge pull request #31844 from woocommerce/fix/28603_tracks_on_payments_tab
Fix Payments tab tracking
This commit is contained in:
commit
0f5a6e251b
|
@ -3075,6 +3075,14 @@ class WC_AJAX {
|
|||
*/
|
||||
public static function toggle_gateway_enabled() {
|
||||
if ( current_user_can( 'manage_woocommerce' ) && check_ajax_referer( 'woocommerce-toggle-payment-gateway-enabled', 'security' ) && isset( $_POST['gateway_id'] ) ) {
|
||||
// Set current tab.
|
||||
$referer = wp_get_referer();
|
||||
if ( $referer ) {
|
||||
global $current_tab;
|
||||
parse_str( wp_parse_url( $referer, PHP_URL_QUERY ), $queries );
|
||||
$current_tab = $queries['tab'] ?? '';
|
||||
}
|
||||
|
||||
// Load gateways.
|
||||
$payment_gateways = WC()->payment_gateways->payment_gateways();
|
||||
|
||||
|
@ -3086,19 +3094,25 @@ class WC_AJAX {
|
|||
continue;
|
||||
}
|
||||
$enabled = $gateway->get_option( 'enabled', 'no' );
|
||||
$option = array(
|
||||
'id' => $gateway->get_option_key()
|
||||
);
|
||||
|
||||
if ( ! wc_string_to_bool( $enabled ) ) {
|
||||
if ( $gateway->needs_setup() ) {
|
||||
wp_send_json_error( 'needs_setup' );
|
||||
wp_die();
|
||||
} else {
|
||||
do_action( 'woocommerce_update_option', $option );
|
||||
$gateway->update_option( 'enabled', 'yes' );
|
||||
}
|
||||
} else {
|
||||
do_action( 'woocommerce_update_option', $option );
|
||||
// Disable the gateway.
|
||||
$gateway->update_option( 'enabled', 'no' );
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_update_options' );
|
||||
wp_send_json_success( ! wc_string_to_bool( $enabled ) );
|
||||
wp_die();
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
|
|||
$this->enable_for_methods = $this->get_option( 'enable_for_methods', array() );
|
||||
$this->enable_for_virtual = $this->get_option( 'enable_for_virtual', 'yes' ) === 'yes';
|
||||
|
||||
// Actions.
|
||||
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||
add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) );
|
||||
add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'change_payment_complete_order_status' ), 10, 3 );
|
||||
|
|
|
@ -70,6 +70,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
$this->description = trim( $this->description );
|
||||
}
|
||||
|
||||
// Actions.
|
||||
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||
add_action( 'woocommerce_order_status_processing', array( $this, 'capture_payment' ) );
|
||||
add_action( 'woocommerce_order_status_completed', array( $this, 'capture_payment' ) );
|
||||
|
|
|
@ -85,7 +85,7 @@ class WC_Settings_Tracking {
|
|||
* Send a Tracks event for WooCommerce options that changed values.
|
||||
*/
|
||||
public function send_settings_change_event() {
|
||||
global $current_tab;
|
||||
global $current_tab, $current_section;
|
||||
|
||||
if ( empty( $this->updated_options ) ) {
|
||||
return;
|
||||
|
@ -98,6 +98,9 @@ class WC_Settings_Tracking {
|
|||
if ( isset( $current_tab ) ) {
|
||||
$properties['tab'] = $current_tab;
|
||||
}
|
||||
if ( isset( $current_section ) ) {
|
||||
$properties['section'] = $current_section;
|
||||
}
|
||||
|
||||
WC_Tracks::record_event( 'settings_change', $properties );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue