array( 'customizer_section' => 'shop_single_recently_viewed_products_section', 'theme_mod_id' => 'single_recently_viewed_products', 'theme_mod_value' => '', ), 'quick-view' => array( 'customizer_section' => 'botiga_section_shop_archive_product_card', 'theme_mod_id' => 'shop_product_quickview_layout', 'theme_mod_value' => 'layout1', ), 'checkout' => array( 'customizer_section' => 'woocommerce_checkout', 'theme_mod_id' => 'shop_checkout_layout', 'theme_mod_value' => 'layout1', ), 'floating-mini-cart' => array( 'customizer_section' => 'side_mini_cart_floating_icon_section', 'theme_mod_id' => 'side_mini_cart_floating_icon', 'theme_mod_value' => '', ), 'side-cart' => array( 'customizer_section' => 'botiga_section_shop_cart', 'theme_mod_id' => 'mini_cart_style', 'theme_mod_value' => 'default', ), 'reasons-to-buy' => array( 'customizer_section' => 'botiga_section_single_product_layout', 'theme_mod_id' => 'single_product_elements_order', 'theme_mod_value' => array( 'botiga_single_product_reasons_to_buy' ), ), 'product-brand-image' => array( 'customizer_section' => 'botiga_section_single_product_layout', 'theme_mod_id' => 'single_product_elements_order', 'theme_mod_value' => array( 'botiga_single_product_brand_image' ), ), 'trust-badges' => array( 'customizer_section' => 'botiga_section_single_product_layout', 'theme_mod_id' => 'single_product_elements_order', 'theme_mod_value' => array( 'botiga_single_product_trust_badge_image' ), ), 'real-time-search' => array( 'customizer_section' => 'botiga_section_shop_search', 'theme_mod_id' => 'shop_search_enable_ajax', 'theme_mod_value' => '', ), 'scroll-to-top-button' => array( 'customizer_section' => 'botiga_section_scrolltotop', 'theme_mod_id' => 'enable_scrolltop', 'theme_mod_value' => '', ), 'size-chart' => array( 'has_module' => true, 'customizer_section' => 'botiga_section_single_product_size_chart', ), 'sticky-add-to-cart' => array( 'has_module' => true, 'customizer_section' => 'botiga_section_single_product_sticky_add_to_cart', ), 'advanced-reviews' => array( 'has_module' => true, 'customizer_section' => 'botiga_section_single_product_advanced_reviews', ), 'buy-now' => array( 'has_module' => true, 'customizer_section' => 'botiga_section_buy_now', ), 'product-video' => array( 'has_module' => true, 'module_id' => 'video-gallery', 'customizer_section' => '', ), 'product-audio' => array( 'has_module' => true, 'module_id' => 'video-gallery', 'customizer_section' => '', ), 'wishlist' => array( 'has_module' => true, 'customizer_section' => 'botiga_section_wishlist', ), 'product-swatches' => array( 'has_module' => true, 'customizer_section' => 'botiga_section_product_swatches', ), 'quick-social-links' => array( 'has_module' => true, 'module_id' => 'quick-links', 'customizer_section' => 'botiga_quicklinks', ), 'address-autocomplete' => array( 'has_module' => true, 'module_id' => 'google-autocomplete', 'customizer_section' => 'botiga_google_autocomplete_section', ), ); /** * Constructor. * */ public function __construct() { if ( ! is_admin() ) { return; } add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_css' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_js' ), 9999 ); add_action( 'wp_ajax_enable_mechant_module', array( $this, 'ajax_enable_merchant_module' ) ); add_action( 'admin_footer', array( $this, 'modal_content' ) ); } /** * Is merchant dashboard page. * */ public function is_merchant_dashboard_page() { global $pagenow; return $pagenow === 'admin.php' && ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] === 'merchant' ); // phpcs:ignore WordPress.Security.NonceVerification } /** * Enqueue admin CSS. * */ public function enqueue_admin_css() { if ( ! $this->is_merchant_dashboard_page() ) { return; } wp_enqueue_style( 'botiga-admin-modal' ); $css = " .merchant-modules-list-item.merchant-module-deactivated-by-bp .merchant-modules-list-item-icon, .merchant-modules-list-item.merchant-module-deactivated-by-bp .merchant-modules-list-item-content { opacity: 1 !important; } .botiga-admin-modal-content { border-radius: 8px; } .botiga-admin-modal-body { position: relative; padding: 40px 30px 30px 40px; } .botiga-admin-close-modal { position: absolute; top: 18px; right: 16px; transition: ease opacity 300ms; } .botiga-admin-close-modal:hover { opacity: 0.7; } .btm-modules-modal h2 { font-size: 18px; font-weight: 700; line-height: 1; margin: 0; } .btm-modules-modal h3 { font-size: 18px; line-height: 1; margin: 0 0 12px 0; } .btm-modules-modal p, .btm-modules-modal a { font-size: 13px; line-height: 1.5; margin: 0; } .btm-modules-modal h2, .btm-modules-modal h3 { color: #212121; } .btm-modules-modal p { color: #757575; } .btm-modules-modal-title { display: flex; align-items: center; justify-content: center; gap: 7px; display: block; max-width: 321px; text-align: center; background-color: #FFFCF6; border: 1px solid #EFBF56; border-radius: 35px; margin: 0px auto 35px !important; padding: 13px 30px 15px; } .btm-modules-modal-title svg { position: relative; top: 3px; } .btm-modules-modal-title-desc { margin-bottom: 30px !important; } .btm-divider { display: none; } @media (min-width: 768px) { .btm-modules-modal-actions { display: flex; gap: 30px; } .btm-modules-modal-actions > div { display: flex; flex-direction: column; flex: 1; } .btm-modules-modal-link { margin-top: auto !important; } .btm-divider { display: block; max-width: 1px; border-right: 1px solid #D9D9D9; } } .btm-modules-modal-actions p { margin-bottom: 22px !important; } .btm-modules-modal-link { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; text-decoration: underline; transition: ease color 300ms; } .btm-modules-modal-link-botiga { color: #212121; } .btm-modules-modal-link-botiga svn path { fill: #212121; transition: ease fill 300ms; } .btm-modules-modal-link-botiga:hover { color: #757575; } .btm-modules-modal-link-botiga:hover svg path { fill: #757575; } .btm-modules-modal-link-merchant { color: #3858E9; } .btm-modules-modal-link-merchant:hover { color: #1A3D9A; } .btm-modules-modal-link-disabled { pointer-events: none; text-decoration: none; color: #757575; box-shadow: none !important; } "; wp_add_inline_style( 'botiga-admin-modal', $css ); } /** * Enqueue admin JS. * */ public function enqueue_admin_js() { if ( ! $this->is_merchant_dashboard_page() ) { return; } wp_enqueue_script( 'botiga-admin-modal' ); wp_localize_script( 'botiga-admin-modal', 'botiga_admin_modal', array( 'loading' => esc_html__( 'Loading...', 'botiga' ), 'redirecting' => esc_html__( 'Redirecting...', 'botiga' ), ) ); $botiga_dashboard_url = add_query_arg( array( 'page' => 'botiga-dashboard' ), admin_url( 'admin.php' ) ); $customize_url = admin_url( 'customize.php' ); $js = " (function($) { adminBotiga.modal.triggerSelector = '.merchant-module-activate.merchant-module-deactivated-by-bp'; $( document ).ready( function() { const customizerSectionsMap = " . wp_json_encode( $this->disable_settings_map ) . "; $( '.botiga-admin-modal' ).on( 'botiga-admin-modal-opened', function(e, modalPopup, modalTrigger) { const merchantModuleId = modalTrigger.data( 'module' ); const modalPopupLink = modalPopup.find( '.btm-modules-modal-link' ); const customizerSection = typeof customizerSectionsMap[merchantModuleId]['customizer_section'] !== 'undefined' ? customizerSectionsMap[merchantModuleId]['customizer_section'] : false; const customizerSectionLink = customizerSection ? '" . esc_js( $customize_url ) . "?autofocus[section]=' + customizerSection : '" . esc_js( $botiga_dashboard_url ) . "'; const enableMerchantLink = modalPopup.find( '.btm-modules-modal-link-merchant' ); modalPopupLink.eq(0).attr( 'href', customizerSectionLink ); enableMerchantLink.data( 'module-id', merchantModuleId ); $( '.btm-modules-modal-link-merchant' ).off( 'click' ).on( 'click', function(e){ e.preventDefault(); const _this = $(this); _this .addClass( 'btm-modules-modal-link-disabled' ) .text( botiga_admin_modal.loading ); $.ajax({ url: ajaxurl, type: 'POST', data: { action: 'enable_mechant_module', module_id: $(this).data( 'module-id' ), nonce: $(this).data( 'nonce' ) }, success: function( response ) { if ( response.success ) { _this.text( botiga_admin_modal.redirecting ); location.href = response.data.redirect; } } }); } ); } ); }); })(jQuery); "; wp_add_inline_script( 'botiga-admin-modal', $js ); } /** * Enable merchant module ajax callback. * * @return void */ public function ajax_enable_merchant_module() { check_ajax_referer( 'btm-enable-merchant-module', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => esc_html__( 'You do not have permission to perform this action', 'botiga' ) ) ); } $module_id = isset( $_POST['module_id'] ) ? sanitize_text_field( $_POST['module_id'] ) : false; if ( ! $module_id ) { wp_send_json_error( array( 'message' => esc_html__( 'Invalid module ID', 'botiga' ) ) ); } $disable_settings_map = $this->disable_settings_map; $module_settings = $disable_settings_map[ $module_id ]; if ( isset( $module_settings['has_module'] ) && $module_settings['has_module'] ) { $botiga_modules = get_option( 'botiga-modules' ); $botiga_modules = ( is_array( $botiga_modules ) ) ? $botiga_modules : (array) $botiga_modules; $mutable_module_id = $module_settings['module_id'] ?? $module_id; if ( in_array( $mutable_module_id, $botiga_modules ) ) { $botiga_modules[ $mutable_module_id ] = false; update_option( 'botiga-modules', $botiga_modules ); } } elseif ( ! is_array( $module_settings['theme_mod_value'] ) ) { set_theme_mod( $module_settings['theme_mod_id'], $module_settings['theme_mod_value'] ); } else { $current_value = get_theme_mod( $module_settings['theme_mod_id'], array() ); if ( is_array( $current_value ) ) { set_theme_mod( $module_settings['theme_mod_id'], array_merge( array_diff( $current_value, $module_settings['theme_mod_value'] ) ) ); } } // Activate merchant module. $mmodules = get_option( Merchant_Modules::$option, array() ); $mmodules[ $module_id ] = true; update_option( Merchant_Modules::$option, $mmodules ); wp_send_json_success( array( 'message' => esc_html__( 'Merchant module enabled', 'botiga' ), 'redirect' => add_query_arg( array( 'page' => 'merchant', 'module' => $module_id ), admin_url( 'admin.php' ) ), ) ); } /** * Modal content. * */ public function modal_content() { if ( ! $this->is_merchant_dashboard_page() ) { return; } ?>