Home Forums Theme Support Dokan override function

This topic is: not resolved

This topic contains 6 replies, has 2 voices, and was last updated by  towhid 3 years, 10 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #45765

    Anas Basalamah
    Member
    Post count: 160

    hi

    I override files from plugin/dokan/include

    i wrote in the function name

    if ( ! function_exists( ‘example' ) ) :

    function example(){
    }
    then in the child theme function file i wrote
    require_once( get_stylesheet_directory() . ‘/includes/template-tags.php' );
    and it works fine

    but now i did the same with to override the function function insert_settings_info() in plugin/dokan/classes/template-settings.php

    but it didn't work

    how to change the function from child theme?

    thanks

    #45938

    towhid
    Participant
    Post count: 4505

    Hello Anas,

    Send me the full code of the function function example() to me. I want to check in my server.

    Thanks

    #45961

    Anas Basalamah
    Member
    Post count: 160

    Ok , I customized this function from includes/ template-tags.php now i can control this function from my child theme
    i created a file child-theme/includes/template-tags.php and i post the function inside it
    also i post this inside child theme function.php

    require_once( get_stylesheet_directory() . ‘/includes/template-tags.php’ );

    the function code

    
    if ( !function_exists( 'dokan_header_user_menu' ) ) :
    
    /**
     * User top navigation menu
     *
     * @return void
     */
    function dokan_header_user_menu() {
        ?>
        <ul class="nav navbar-nav navbar-right">
    	
    	        <?php if ( is_user_logged_in() ) { ?>
    
    	            <li><?php wp_loginout( home_url() ); ?></li>
    <?php } ?>
            <li>
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php printf( __( 'Cart %s', 'dokan' ), '<span class="dokan-cart-amount-top">(' . WC()->cart->get_cart_total() . ')</span>' ); ?> <b class="caret"></b></a>
    
                <ul class="dropdown-menu">
                    <li>
                        <div class="widget_shopping_cart_content"></div>
                    </li>
                </ul>
            </li>
    
            <?php if ( is_user_logged_in() ) { ?>
    
                <?php
                global $current_user;
    
                $user_id = $current_user->ID;
                if ( dokan_is_user_seller( $user_id ) ) {
                    ?>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php _e( 'Seller Dashboard', 'dokan' ); ?> <b class="caret"></b></a>
    
                        <ul class="dropdown-menu">
                            <li><a href="<?php echo dokan_get_store_url( $user_id ); ?>" target="_blank"><?php _e( 'Visit your store', 'dokan' ); ?> <i class="fa fa-external-link"></i></a></li>
                            <li class="divider"></li>
                            <?php
                            $nav_urls = dokan_get_dashboard_nav();
    
                            foreach ($nav_urls as $key => $item) {
                                printf( '<li><a href="%s">%s  %s</a></li>', $item['url'], $item['icon'], $item['title'] );
                            }
                            ?>
                        </ul>
                    </li>
                <?php } ?>
    
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo esc_html( $current_user->display_name ); ?> <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="<?php echo dokan_get_page_url( 'my_orders' ); ?>"><?php _e( 'My Orders', 'dokan' ); ?></a></li>
                        <li><a href="<?php echo dokan_get_page_url( 'myaccount', 'woocommerce' ); ?>"><?php _e( 'My Account', 'dokan' ); ?></a></li>
                        <li><a href="<?php echo wc_customer_edit_account_url(); ?>"><?php _e( 'Edit Account', 'dokan' ); ?></a></li>
                        <li class="divider"></li>
                        <li><a href="<?php echo wc_get_endpoint_url( 'edit-address', 'billing', get_permalink( wc_get_page_id( 'myaccount' ) ) ); ?>"><?php _e( 'Billing Address', 'dokan' ); ?></a></li>
                        <li><a href="<?php echo wc_get_endpoint_url( 'edit-address', 'shipping', get_permalink( wc_get_page_id( 'myaccount' ) ) ); ?>"><?php _e( 'Shipping Address', 'dokan' ); ?></a></li>
                    </ul>
                </li>
    
            <?php } else { ?>
                <li><a href="<?php echo dokan_get_page_url( 'myaccount', 'woocommerce' ); ?>"><?php _e( 'Log in', 'dokan' ); ?></a></li>
                <li><a href="<?php echo dokan_get_page_url( 'myaccount', 'woocommerce' ); ?>"><?php _e( 'Sign Up', 'dokan' ); ?></a></li>
            <?php } ?>
        </ul>
        <?php
    }
    
    endif;
    

    now i want to customize function insert_settings_info() in plugin/dokan/classes/template-settings.php
    i tried to do it the same way as the function above but its not working

    is there another way ?

    thanks

    #46121

    Anas Basalamah
    Member
    Post count: 160

    any news?

    #46124

    towhid
    Participant
    Post count: 4505

    Hello Anas,

    Sorry for my late reply.

    Here is the solution:

    Please open plugins/dokan/classes/template-settings.php

    and find function insert_settings_info() {

    now, replace total function code of function insert_settings_info() { with below code and let me know the result.

    if ( !function_exists( 'insert_settings_info' ) ):
            function insert_settings_info() {
    
                $store_id            = get_current_user_id();
                $prev_dokan_settings = get_user_meta( $store_id, 'dokan_profile_settings', true );
    
                if ( wp_verify_nonce( $_POST['_wpnonce'], 'dokan_profile_settings_nonce' ) ) {
    
                    // update profile settings info
                    $social         = $_POST['settings']['social'];
                    $social_fields  = dokan_get_social_profile_fields();
                    $dokan_settings = array( 'social' => array() );
    
                    if ( is_array( $social ) ) {
                        foreach ($social as $key => $value) {
                            if ( isset( $social_fields[ $key ] ) ) {
                                $dokan_settings['social'][ $key ] = filter_var( $social[ $key ], FILTER_VALIDATE_URL );
                            }
                        }
                    }
    
                } elseif ( wp_verify_nonce( $_POST['_wpnonce'], 'dokan_store_settings_nonce' ) ) {
    
                    //update store setttings info
                    $dokan_settings = array(
                        'store_name'   => sanitize_text_field( $_POST['dokan_store_name'] ),
                        'address'      => strip_tags( $_POST['setting_address'] ),
                        'location'     => sanitize_text_field( $_POST['location'] ),
                        'find_address' => sanitize_text_field( $_POST['find_address'] ),
                        'banner'       => absint( $_POST['dokan_banner'] ),
                        'phone'        => sanitize_text_field( $_POST['setting_phone'] ),
                        'show_email'   => sanitize_text_field( $_POST['setting_show_email'] ),
                        'gravatar'     => absint( $_POST['dokan_gravatar'] ),
                    );
    
                } elseif ( wp_verify_nonce( $_POST['_wpnonce'], 'dokan_payment_settings_nonce' ) ) {
    
                    //update payment settings info
                    $dokan_settings = array(
                        'payment'      => array(),
                    );
    
                    if ( isset( $_POST['settings']['bank'] ) ) {
                        $bank = $_POST['settings']['bank'];
    
                        $dokan_settings['payment']['bank'] = array(
                            'ac_name'   => sanitize_text_field( $bank['ac_name'] ),
                            'ac_number' => sanitize_text_field( $bank['ac_number'] ),
                            'bank_name' => sanitize_text_field( $bank['bank_name'] ),
                            'bank_addr' => sanitize_text_field( $bank['bank_addr'] ),
                            'swift'     => sanitize_text_field( $bank['swift'] ),
                        );
                    }
    
                    if ( isset( $_POST['settings']['paypal'] ) ) {
                        $dokan_settings['payment']['paypal'] = array(
                            'email' => filter_var( $_POST['settings']['paypal']['email'], FILTER_VALIDATE_EMAIL )
                        );
                    }
    
                    if ( isset( $_POST['settings']['skrill'] ) ) {
                        $dokan_settings['payment']['skrill'] = array(
                            'email' => filter_var( $_POST['settings']['skrill']['email'], FILTER_VALIDATE_EMAIL )
                        );
                    }
    
                }
    
                $dokan_settings = array_merge($prev_dokan_settings,$dokan_settings);
    
                $profile_completeness = $this->calculate_profile_completeness_value( $dokan_settings );
                $dokan_settings['profile_completion'] = $profile_completeness;
    
                update_user_meta( $store_id, 'dokan_profile_settings', $dokan_settings );
    
                do_action( 'dokan_store_profile_saved', $store_id, $dokan_settings );
    
                if ( ! defined( 'DOING_AJAX' ) ) {
                    $_GET['message'] = 'profile_saved';
                }
            }
        endif;

    Thanks

    #46126

    Anas Basalamah
    Member
    Post count: 160

    ok but can you tell me what is the different?

    you just added if exist?

    #46132

    towhid
    Participant
    Post count: 4505

    Hello Anas,

    Please check this link to know about the override function in parent theme- http://www.wpthemedetector.com/add-functions-to-your-wordpress-child-theme-1/

    Thanks

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘override function’ is closed to new replies.