'General', 'woocommerce' => 'WooCommerce', 'whatsapp_chat_button' => 'WhatsApp Chat Button', 'api' => 'API', 'advanced' => 'Advanced', ); if ( ! class_exists( 'WooCommerce' ) ) { unset($tabs['woocommerce']); } return $tabs; } /** * Check if on settings page */ public static function is_settings_page() { $current_page = isset($_GET['page']) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; return strpos($current_page, NOTIFIER_NAME . '-settings') !== false; } /** * Settings fields */ private static function settings_fields($tab) { $api_key = get_option(NOTIFIER_PREFIX . 'api_key'); if(Notifier::is_api_active() && '' != $api_key) { $disabled = true; $description = 'You are successfully connected to WANotifier.com. Disconnect.'; } else{ $disabled = false; $description = 'You are not connected to WANotifier.com yet. Please enter valid API key and save the settings. You can get your WANotifier.com API Key from here.'; } $settings = array(); switch ($tab) { case 'general': $settings = array( array( 'title' => 'General', 'type' => 'title', 'description' => '' ), array( 'id' => 'default_country_code', 'title' => 'Default Country Code (Optional)', 'type' => 'text', 'placeholder' => 'Eg. +91', 'description' => 'Enter default country code that will be added to all recipient phone number fields before sending to WANotifier that do not start with a + sign.', 'default' => '' ), ); break; case 'whatsapp_chat_button': $settings = array( array( 'title' => 'WhatsApp Chat Button', 'description' => 'Add a WhatsApp chat button to your website to let your visitors start chat with you on WhatsApp.', 'type' => 'title', ), array( 'id' => 'ctc_enable', 'title' => 'Enable', 'type' => 'checkbox', 'default' => '', 'name' => 'ctc_enable', ), array( 'id' => 'ctc_whatsapp_number', 'title' => 'Whatsapp Number', 'type' => 'text', 'placeholder' => 'Enter your WhatsApp number', 'name' => 'ctc_whatsapp_number', 'description' => 'Enter your WhatsApp number with country code. Eg. +919876543210', ), array( 'id' => 'ctc_greeting_text', 'title' => 'Greeting Message', 'type' => 'text', 'name' => 'ctc_greeting_text', 'placeholder' => 'Enter your greeting message here', 'description' => 'This text will be added to user\'s WhatsApp chat text field when they click on the button.' , ), array( 'id' => 'ctc_button_style', 'title' => 'Button Style', 'name' => 'ctc_button_style', 'class' => 'chat-button-style', 'type' => 'select', 'default' => '', 'options' => self::get_button_styles(), 'description' => 'Select a button style. Preview will be shown on bottom right of this screen. You can update button style by writing custom CSS in your theme.', ), array( 'id' => 'ctc_custom_button_image_url', 'title' => 'Button image url', 'type' => 'text', 'placeholder' => 'https://', 'name' => 'ctc_custom_button_image_url', 'description' => 'Enter button image url here.', 'tr_class' => 'notifier-chat-btn-image-url', ), ); break; case 'api': $settings = array( array( 'title' => 'API Configuration', 'description' => '', 'type' => 'title', ), array( 'id' => 'api_key', 'title' => 'WANotifier.com API key', 'type' => 'text', 'placeholder' => 'Enter your WANotifier.com API key here', 'default' => '', 'description' => $description, 'disabled' => $disabled ), ); break; case 'advanced': $settings = array( array( 'title' => 'Advanced Settings', 'description' => '', 'type' => 'title', ), array( 'id' => 'hidden_custom_keys', 'title' => 'Hidden custom meta keys', 'type' => 'checkbox', 'label' => 'Enable', 'description' => 'Enable hidden custom meta keys that start with underscores (e.g. _field_name) to be avaialbe in Data and Recipient Fields. Note that enabling this might impact your website performance slightly.', 'default' => '' ), array( 'id' => 'enable_async_triggers', 'title' => 'Async triggers', 'type' => 'checkbox', 'default' => '', 'label' => 'Enable', 'name' => 'enable_async_triggers', 'description' => 'Plugin slowing down checkout or form submission? Enable this option to send triggers asynchronously using Action Scheduler. Note that if you have a site with strong caching, this might not work as expected.' , ), array( 'id' => 'enable_activity_log', 'title' => 'Activity log', 'type' => 'checkbox', 'default' => '', 'label' => 'Enable', 'name' => 'enable_activity_log', 'description' => 'Enabling this option will activate the activity logging feature. You can view activity logs here.' , ), ); break; case 'woocommerce': if ( class_exists( 'WooCommerce' ) ) { $settings = array( array( 'title' => 'Checkout', 'description' => '', 'type' => 'title', ), array( 'id' => 'enable_opt_in_checkbox_checkout', 'title' => 'Opt-in Consent on Checkout', 'type' => 'checkbox', 'default' => '', 'label' => 'Enable', 'name' => 'enable_opt_in_checkbox_checkout', 'description' => 'Add an opt-in checkbox to WooCommerce checkout form. Once enabled, WhatsApp notification will be sent only to customers who opt-in during checkout.' ), array( 'id' => 'checkout_opt_in_checkbox_text', 'title' => 'Opt-in Checkbox Text', 'type' => 'textarea', 'placeholder' => 'Enter text for the opt-in checkbox', 'default' => 'Receive updates on WhatsApp', 'name' => 'checkout_opt_in_checkbox_text', ), array( 'title' => 'Abandoned Cart', 'description' => '', 'type' => 'title', ), array( 'id' => 'enable_abandonment_cart_tracking', 'title' => 'Abandoned cart tracking', 'type' => 'checkbox', 'default' => '', 'label' => 'Start capturing abandoned carts', 'name' => 'enable_abandonment_cart_tracking', 'description' => 'Enable this to start capturing abandoned carts in database. Carts will be considered as abandoned if order is not placed by the user after adding items in the cart within cart abandoned cut-off time set below.' ), array( 'id' => 'abandonment_cart_cron_run_time', 'title' => 'Cart abandoned cut-off time', 'type' => 'number', 'placeholder' => 'Enter time in minutes. Eg. 20', 'description' => 'Enter time in minutes after which the cart will be considered as abandoned. This is the time from when items are added / updated in cart.', 'default' => '20', 'custom_attributes' => array('min' => 20), ), ); } break; } $settings = apply_filters( 'notifier_$tab_settings_fields', $settings ); return $settings; } /** * Generate HTML for displaying individual fields */ public static function display_field( $field ) { $field = wp_parse_args($field, array( 'title' => '', 'description' => '', 'label' => '' )); $html = ''; if (isset($field['id'])) { $option_name = NOTIFIER_PREFIX . $field['id']; $option = get_option( $option_name ); } $data = isset($option) ? $option : ''; if ( isset( $field['default'] ) && empty($option) ) { $data = $field['default']; } $custom_attributes = array(); if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { foreach ( $field['custom_attributes'] as $attribute => $value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; } } if ( isset($field['required']) && $field['required'] ) { $custom_attributes[] = 'required="required"'; } if ( isset($field['disabled']) && $field['disabled'] ) { $custom_attributes[] = 'disabled="disabled"'; } if(isset($field['tr_class'])){ $tr_class = $field['tr_class']; }else{ $tr_class = ''; } $custom_attributes_string = implode( ' ', $custom_attributes ); if ( 'title' === $field['type']) { $html .= '
' . $field['description'] . '