diff --git a/assets/react/admin-dashboard/segments/options.js b/assets/react/admin-dashboard/segments/options.js index 3b5ae74bf9..bd8f2d49eb 100644 --- a/assets/react/admin-dashboard/segments/options.js +++ b/assets/react/admin-dashboard/segments/options.js @@ -616,16 +616,46 @@ document.addEventListener('DOMContentLoaded', function () { const invoice_field = document.querySelector("[name='tutor_option[tutor_woocommerce_invoice]']"); const invoice_field_wrapper = document.getElementById('field_tutor_woocommerce_invoice'); + const ecommerce_pages = document.querySelector('.ecommerce_pages'); + const ecommerce_currency = document.querySelector('.ecommerce_currency'); + const revenue_sharing_checkbox = document.querySelector('[data-toggle-fields="sharing_percentage"]') + const revenue_sharing_field = document.querySelector("[name='tutor_option[enable_revenue_sharing]']"); + const revenue_sharing_section = document.querySelector('.revenue_sharing'); + const fees_section = document.querySelector('.fees'); + const withdraw_section = document.querySelector('.withdraw'); if (invoice_field) { showHideOption(invoice_field_wrapper, monetization_field.value, 'wc') } if (monetization_field) { - showHideOption(order_autocomplete_wrapper, monetization_field.value, 'wc'); + const monetized_by = monetization_field?.value; + /** + * Show/Hide on saved value. + */ + showHideOption(order_autocomplete_wrapper, monetized_by, 'wc'); + showHideOption(ecommerce_pages, monetized_by, 'tutor'); + showHideOption(ecommerce_currency, monetized_by, 'tutor'); + + /** + * Show/Hide on-change value change. + */ monetization_field.onchange = (e) => { showHideOption(order_autocomplete_wrapper, e.target.value, 'wc'); showHideOption(invoice_field_wrapper, e.target.value, 'wc'); + + showHideOption(ecommerce_pages, e.target.value, 'tutor'); + showHideOption(ecommerce_currency, e.target.value, 'tutor'); + } + } + + if (revenue_sharing_field) { + showHideOption(fees_section, revenue_sharing_field.value, 'on'); + showHideOption(withdraw_section, revenue_sharing_field.value, 'on'); + + revenue_sharing_checkbox.onchange = (e) => { + showHideOption(fees_section, e.target.checked, true); + showHideOption(withdraw_section, e.target.checked, true); } } diff --git a/assets/scss/admin-dashboard/v2/components/_nav-tab.scss b/assets/scss/admin-dashboard/v2/components/_nav-tab.scss index 0e23de5b84..22bbce8d0f 100644 --- a/assets/scss/admin-dashboard/v2/components/_nav-tab.scss +++ b/assets/scss/admin-dashboard/v2/components/_nav-tab.scss @@ -29,6 +29,10 @@ border-color: #e8e8e8; } } + + .tutor-option-submenu-nav{ + margin-left: 28px; + } } &.tutor-is-sticky { position: sticky; diff --git a/classes/Options_V2.php b/classes/Options_V2.php index abafbe4b23..82fa28f659 100644 --- a/classes/Options_V2.php +++ b/classes/Options_V2.php @@ -137,6 +137,25 @@ public static function get_only( $only = array() ) { return array_intersect_key( $settings, array_flip( $only ) ); } + /** + * Prepare settings search item. + * + * @since 3.0.0 + * + * @param array $section section item. + * @param array $block block item. + * @param array $field field item. + * + * @return array prepared searchable field item. + */ + private function prepare_search_item( $section, $block, $field ) { + $field['section_label'] = isset( $section['label'] ) ? $section['label'] : ''; + $field['section_slug'] = isset( $section['slug'] ) ? $section['slug'] : ''; + $field['block_label'] = isset( $block['label'] ) ? $block['label'] : ''; + + return $field; + } + /** * Function to get all fields for search tutor_option_search * @@ -150,14 +169,28 @@ public function tutor_option_search() { $data_array = array(); foreach ( $this->get_setting_fields() as $sections ) { if ( is_array( $sections ) && ! empty( $sections ) ) { - foreach ( tutils()->sanitize_recursively( $sections ) as $section ) { + foreach ( tutor_utils()->sanitize_recursively( $sections ) as $section ) { foreach ( $section['blocks'] as $blocks ) { if ( isset( $blocks['fields'] ) && ! empty( $blocks['fields'] ) ) { foreach ( $blocks['fields'] as $fields ) { - $fields['section_label'] = isset( $section['label'] ) ? $section['label'] : ''; - $fields['section_slug'] = isset( $section['slug'] ) ? $section['slug'] : ''; - $fields['block_label'] = isset( $blocks['label'] ) ? $blocks['label'] : ''; - $data_array['fields'][] = $fields; + $data_array['fields'][] = $this->prepare_search_item( $section, $blocks, $fields ); + } + } + } + + /** + * Submenu item search. + * + * @since 3.0.0 + */ + if ( isset( $section['submenu'] ) && is_array( $section['submenu'] ) ) { + foreach ( tutor_utils()->sanitize_recursively( $section['submenu'] ) as $submenu_section ) { + foreach ( $submenu_section['blocks'] as $block ) { + if ( isset( $block['fields'] ) && ! empty( $block['fields'] ) ) { + foreach ( $block['fields'] as $fields ) { + $data_array['fields'][] = $this->prepare_search_item( $submenu_section, $block, $fields ); + } + } } } } @@ -918,11 +951,11 @@ public function get_setting_fields() { 'monetization' => array( 'label' => __( 'Monetization', 'tutor' ), 'slug' => 'monetization', - 'desc' => __( 'Monitization Settings', 'tutor' ), + 'desc' => __( 'Monetization Settings', 'tutor' ), 'template' => 'basic', 'icon' => 'tutor-icon-badge-discount', 'blocks' => array( - 'block_options' => array( + 'block_options' => array( 'label' => __( 'Options', 'tutor' ), 'slug' => 'options', 'block_type' => 'uniform', @@ -949,6 +982,22 @@ public function get_setting_fields() { 'default' => 'off', 'desc' => __( 'If enabled, in the case of Courses, WooCommerce Orders will get the "Completed" status .', 'tutor' ), ), + array( + 'key' => 'statement_show_per_page', + 'type' => 'number', + 'number_type' => 'integer', + 'label' => __( 'Show Statement Per Page', 'tutor' ), + 'default' => '20', + + 'desc' => __( 'Define the number of statements to show.', 'tutor' ), + ), + ), + ), + 'block_revenue_sharing' => array( + 'label' => __( 'Revenue Sharing', 'tutor' ), + 'slug' => 'revenue_sharing', + 'block_type' => 'uniform', + 'fields' => array( array( 'key' => 'enable_revenue_sharing', 'type' => 'toggle_switch', @@ -980,18 +1029,9 @@ public function get_setting_fields() { ), 'desc' => __( 'Set how the sales revenue will be shared among admins and instructors.', 'tutor' ), ), - array( - 'key' => 'statement_show_per_page', - 'type' => 'number', - 'number_type' => 'integer', - 'label' => __( 'Show Statement Per Page', 'tutor' ), - 'default' => '20', - - 'desc' => __( 'Define the number of statements to show.', 'tutor' ), - ), ), ), - array( + 'block_fees' => array( 'label' => __( 'Fees', 'tutor' ), 'slug' => 'fees', 'block_type' => 'uniform', @@ -1037,7 +1077,7 @@ public function get_setting_fields() { ), ), ), - array( + 'block_withdraw' => array( 'label' => __( 'Withdraw', 'tutor' ), 'slug' => 'withdraw', 'block_type' => 'uniform', @@ -1652,8 +1692,11 @@ public function get_setting_fields() { 'type' => 'text', 'label' => __( 'YouTube API Key', 'tutor' ), 'default' => '', - 'desc' => __( 'To host live videos on your platform using YouTube, enter your YouTube API key. -Text inside the box: Insert API key here.', 'tutor' ), + 'desc' => __( + 'To host live videos on your platform using YouTube, enter your YouTube API key. + Text inside the box: Insert API key here.', + 'tutor' + ), ), ), ), diff --git a/ecommerce/Settings.php b/ecommerce/Settings.php index e424cb20b4..650c7f3544 100644 --- a/ecommerce/Settings.php +++ b/ecommerce/Settings.php @@ -40,109 +40,100 @@ public function __construct() { public static function add_ecommerce_settings( $fields ) { $pages = tutor_utils()->get_pages(); - $arr['ecommerce_basic'] = array( - 'label' => __( 'Basic', 'tutor' ), - 'slug' => 'ecommerce_basic', - 'desc' => __( 'Advanced Settings', 'tutor' ), - 'template' => 'basic', - 'icon' => 'tutor-icon-gear', - 'blocks' => array( - array( - 'label' => false, - 'block_type' => 'uniform', - 'slug' => 'cart_page', - 'fields' => array( - array( - 'key' => CartController::PAGE_ID_OPTION_NAME, - 'type' => 'select', - 'label' => __( 'Cart Page', 'tutor' ), - 'default' => '0', - 'options' => $pages, - 'desc' => __( 'Select the page you wish to set as the cart page.', 'tutor' ), - 'searchable' => true, - ), + $basic_settings_blocks = array( + 'ecommerce_block_pages' => array( + 'label' => false, + 'block_type' => 'uniform', + 'slug' => 'ecommerce_pages', + 'fields' => array( + array( + 'key' => CartController::PAGE_ID_OPTION_NAME, + 'type' => 'select', + 'label' => __( 'Cart Page', 'tutor' ), + 'default' => '0', + 'options' => $pages, + 'desc' => __( 'Select the page you wish to set as the cart page.', 'tutor' ), + 'searchable' => true, ), - ), - array( - 'label' => false, - 'block_type' => 'uniform', - 'slug' => 'checkout_page', - 'fields' => array( - array( - 'key' => CheckoutController::PAGE_ID_OPTION_NAME, - 'type' => 'select', - 'label' => __( 'Checkout Page', 'tutor' ), - 'default' => '0', - 'options' => $pages, - 'desc' => __( 'Select the page to be used as the checkout page.', 'tutor' ), - 'searchable' => true, - ), + array( + 'key' => CheckoutController::PAGE_ID_OPTION_NAME, + 'type' => 'select', + 'label' => __( 'Checkout Page', 'tutor' ), + 'default' => '0', + 'options' => $pages, + 'desc' => __( 'Select the page to be used as the checkout page.', 'tutor' ), + 'searchable' => true, ), ), - array( - 'label' => __( 'Currency', 'tutor' ), - 'slug' => 'currency', - 'block_type' => 'uniform', - 'fields' => array( - array( - 'key' => OptionKeys::CURRENCY_CODE, - 'type' => 'select', - 'label' => __( 'Currency Symbol', 'tutor' ), - 'select_options' => false, - 'options' => self::get_currency_options(), - 'default' => 'USD', - 'desc' => __( 'Choose the currency for transactions.', 'tutor' ), - 'searchable' => true, - ), - array( - 'key' => OptionKeys::CURRENCY_POSITION, - 'type' => 'select', - 'label' => __( 'Currency Position', 'tutor' ), - 'select_options' => false, - 'options' => array( - 'left' => 'Left', - 'right' => 'Right', - ), - 'default' => 'left', - 'desc' => __( 'Set the position of the currency symbol.', 'tutor' ), - ), - array( - 'key' => OptionKeys::THOUSAND_SEPARATOR, - 'type' => 'text', - 'label' => __( 'Thousand Separator', 'tutor' ), - 'default' => ',', - 'desc' => __( 'Specify the thousand separator.', 'tutor' ), - ), - array( - 'key' => OptionKeys::DECIMAL_SEPARATOR, - 'type' => 'text', - 'label' => __( 'Decimal Separator', 'tutor' ), - 'default' => '.', - 'desc' => __( 'Specify the decimal separator.', 'tutor' ), - ), - array( - 'key' => OptionKeys::NUMBER_OF_DECIMALS, - 'type' => 'number', - 'label' => __( 'Number of Decimals', 'tutor' ), - 'default' => '2', - 'desc' => __( 'Set the number of decimal places.', 'tutor' ), + ), + 'ecommerce_block_currency' => array( + 'label' => __( 'Currency', 'tutor' ), + 'slug' => 'ecommerce_currency', + 'block_type' => 'uniform', + 'fields' => array( + array( + 'key' => OptionKeys::CURRENCY_CODE, + 'type' => 'select', + 'label' => __( 'Currency Symbol', 'tutor' ), + 'select_options' => false, + 'options' => self::get_currency_options(), + 'default' => 'USD', + 'desc' => __( 'Choose the currency for transactions.', 'tutor' ), + 'searchable' => true, + ), + array( + 'key' => OptionKeys::CURRENCY_POSITION, + 'type' => 'select', + 'label' => __( 'Currency Position', 'tutor' ), + 'select_options' => false, + 'options' => array( + 'left' => 'Left', + 'right' => 'Right', ), + 'default' => 'left', + 'desc' => __( 'Set the position of the currency symbol.', 'tutor' ), + ), + array( + 'key' => OptionKeys::THOUSAND_SEPARATOR, + 'type' => 'text', + 'label' => __( 'Thousand Separator', 'tutor' ), + 'default' => ',', + 'desc' => __( 'Specify the thousand separator.', 'tutor' ), + ), + array( + 'key' => OptionKeys::DECIMAL_SEPARATOR, + 'type' => 'text', + 'label' => __( 'Decimal Separator', 'tutor' ), + 'default' => '.', + 'desc' => __( 'Specify the decimal separator.', 'tutor' ), + ), + array( + 'key' => OptionKeys::NUMBER_OF_DECIMALS, + 'type' => 'number', + 'label' => __( 'Number of Decimals', 'tutor' ), + 'default' => '2', + 'desc' => __( 'Set the number of decimal places.', 'tutor' ), ), ), - ), + ); - $arr = apply_filters( 'tutor_after_ecommerce_basic_settings', $arr ); + foreach ( $basic_settings_blocks as $key => $block_item ) { + $fields['monetization']['blocks'][ $key ] = $block_item; + } + + $arr = apply_filters( 'tutor_before_ecommerce_payment_settings', array() ); $arr['ecommerce_payment'] = array( - 'label' => __( 'Payment', 'tutor' ), + 'label' => __( 'Payment Methods', 'tutor' ), 'slug' => 'automate_payment_gateway', 'desc' => __( 'Advanced Settings', 'tutor' ), 'template' => 'basic', 'icon' => 'tutor-icon-credit-card', 'blocks' => array(), ); + // @TODO. // $arr['ecommerce_tax'] = array( // 'label' => __( 'Tax', 'tutor' ), @@ -217,7 +208,9 @@ public static function add_ecommerce_settings( $fields ) { ), ); - return apply_filters( 'tutor_after_ecommerce_settings', $fields + $arr ); + $fields['monetization']['submenu'] = $arr; + + return apply_filters( 'tutor_after_ecommerce_settings', $fields ); } /** @@ -256,7 +249,7 @@ public static function ajax_add_manual_payment_method() { } $request = Input::sanitize_array( - $_POST, + $_POST, //phpcs:ignore -- already sanitized. array( 'additional_details' => 'sanitize_textarea_field', 'payment_instructions' => 'sanitize_textarea_field', @@ -433,7 +426,7 @@ public static function add_payment_gateway_settings( $settings ): array { 'fields' => array(), ); - array_push( $settings['ecommerce_payment']['blocks'], $payment_gateway ); + array_push( $settings['monetization']['submenu']['ecommerce_payment']['blocks'], $payment_gateway ); foreach ( self::get_default_automate_payment_gateways() as $key => $gateway ) { @@ -452,7 +445,8 @@ public static function add_payment_gateway_settings( $settings ): array { 'label' => $gateway['label'], 'label_title' => '', 'default' => 'off', - 'desc' => sprintf( __( 'Enable %s payment', 'tutor-pro' ), $gateway['label'] ), + /* translators: %s: gateway name */ + 'desc' => sprintf( __( 'Enable %s payment', 'tutor' ), $gateway['label'] ), 'toggle_fields' => implode( ',', array_keys( self::$config_keys_method() ) ), ), ); @@ -463,7 +457,7 @@ public static function add_payment_gateway_settings( $settings ): array { $new_gateway['fields'] = $fields; // Append new gateways inside ecommerce payment. - $settings['ecommerce_payment']['blocks'][] = $new_gateway; + $settings['monetization']['submenu']['ecommerce_payment']['blocks'][] = $new_gateway; } $settings = apply_filters( 'tutor_ecommerce_payment_settings', $settings ); @@ -473,7 +467,7 @@ public static function add_payment_gateway_settings( $settings ): array { 'action' => 'add_more_automate_payment_gateway', ); - array_push( $settings['ecommerce_payment']['blocks'], $add_more_gateway ); + array_push( $settings['monetization']['submenu']['ecommerce_payment']['blocks'], $add_more_gateway ); // Manual Payments. $manual_gateways = array( @@ -483,12 +477,12 @@ public static function add_payment_gateway_settings( $settings ): array { 'fields' => array(), ); - array_push( $settings['ecommerce_payment']['blocks'], $manual_gateways ); + array_push( $settings['monetization']['submenu']['ecommerce_payment']['blocks'], $manual_gateways ); $manual_gateways = self::get_manual_payment_setting_fields(); foreach ( $manual_gateways as $gateway ) { - array_push( $settings['ecommerce_payment']['blocks'], $gateway ); + array_push( $settings['monetization']['submenu']['ecommerce_payment']['blocks'], $gateway ); } $add_btn = array( @@ -496,7 +490,7 @@ public static function add_payment_gateway_settings( $settings ): array { 'action' => 'add_manual_payment_btn', ); - array_push( $settings['ecommerce_payment']['blocks'], $add_btn ); + array_push( $settings['monetization']['submenu']['ecommerce_payment']['blocks'], $add_btn ); return $settings; } @@ -565,6 +559,7 @@ public static function get_manual_payment_setting_fields() { 'fields' => array(), 'payment_method_id' => $method_id, 'default' => $is_enable, + /* translators: %s: payment method name */ 'desc' => sprintf( __( 'Enable %s payment method', 'tutor' ), $method_name ), 'data-attrs' => array( 'is-enable' => $is_enable, @@ -670,24 +665,28 @@ public static function get_config_fields( string $gateway ): array { $config_fields = array(); foreach ( $config_keys as $key => $type ) { + $key_label = ucfirst( str_replace( '_', ' ', $key ) ); + /* translators: %s: key label */ + $placeholder = sprintf( __( 'Enter your %s here', 'tutor' ), $key_label ); + if ( 'environment' === $type ) { $config_fields[] = array( 'key' => $key, 'type' => 'select', 'default' => array_keys( self::get_payment_environments() )[0], 'options' => self::get_payment_environments(), - 'label' => __( ucfirst( str_replace( '_', ' ', $key ) ), 'tutor-pro' ), + 'label' => $key_label, 'select_options' => false, 'desc' => '', - 'placeholder' => __( 'Enter your ' . ucfirst( str_replace( '_', ' ', $key ) ) . ' here', 'tutor-pro' ), + 'placeholder' => $placeholder, ); } else { $config_fields[] = array( 'key' => $key, 'type' => $type, - 'label' => __( ucfirst( str_replace( '_', ' ', $key ) ), 'tutor-pro' ), + 'label' => $key_label, 'desc' => '', - 'placeholder' => __( 'Enter your ' . ucfirst( str_replace( '_', ' ', $key ) ) . ' here', 'tutor-pro' ), + 'placeholder' => $placeholder, ); } } diff --git a/views/options/settings.php b/views/options/settings.php index 44469be0bb..9d535cf34e 100644 --- a/views/options/settings.php +++ b/views/options/settings.php @@ -46,12 +46,7 @@
-
+ + - @@ -125,6 +116,26 @@ ?> $section ) : + $active_class = $active_tab === $key ? esc_attr( ' is-active' ) : ''; + ?> +
+ template( $section ); //phpcs:ignore -- contain safe data + } + ?> +
+