• Resolved ewomazino

    (@ewomazino)


    Hello

    Dokan has a function that displays whether a vendor is open or closed based on the opening and closing hours set by the vendor BUT this is displayed only on the vendor store page.
    However, a customer can still purchase a product without knowing if the vendor is open or closed.

    I would be nice to display a notice on the single product page just below the product image, stating that the vendor is closed.
    something like “This Vendor is: Closed”

    Any help would be greatly appreciated.

    Thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • Hello @ewomazino ,

    I have prepared a custom code that will show the store opening and closing message on top of add to cart button –

    add_action('woocommerce_before_add_to_cart_form', 'dokan_open_close');
    
    function dokan_open_close() {
        $store_user  = dokan()->vendor->get( get_query_var( 'author' ) );
        $store_info  = $store_user->get_shop_info();
        $dokan_store_time_enabled = isset( $store_info['dokan_store_time_enabled'] ) ? $store_info['dokan_store_time_enabled'] : '';
        $dokan_store_time_enabled = isset( $store_info['dokan_store_time_enabled'] ) ? $store_info['dokan_store_time_enabled'] : '';
        $store_open_notice        = isset( $store_info['dokan_store_open_notice'] ) && ! empty( $store_info['dokan_store_open_notice'] ) ? $store_info['dokan_store_open_notice'] : __( 'Store Open', 'dokan-lite' );
        $store_closed_notice      = isset( $store_info['dokan_store_close_notice'] ) && ! empty( $store_info['dokan_store_close_notice'] ) ? $store_info['dokan_store_close_notice'] : __( 'Store Closed', 'dokan-lite' );
        $show_store_open_close    = dokan_get_option( 'store_open_close', 'dokan_appearance', 'on' );
    
        if ( $show_store_open_close == 'on' && $dokan_store_time_enabled == 'yes') { ?>
            <div class="dokan-store-open-close">
                <i class="fa fa-shopping-cart"></i>
                <?php if ( dokan_is_store_open( $store_user->get_id() ) ) {
                    echo esc_attr( $store_open_notice );
                } else {
                    echo esc_attr( $store_closed_notice );
                } ?>
            </div>
    
            <?php 
        }
    }

    If you want to move the message to anywhere else, just use the proper WooCommerce hooks.

    Thank you.

    Clearly a must have feature for a marketplace ! I already asked for this in the past without help on it so thanks a lot Rashed Ripon for your custom code ??

    Unfortunately, I added it and nothing appears ??

    Thread Starter ewomazino

    (@ewomazino)

    Hello @rur165

    Thanks for your reply.

    I placed the code snippet in functions.php file of my child theme but it didn’t quite do the job. Perhaps you want to take a second look.

    Thanks for the effort.

    Hello @ewomazino & @agonza26 ,

    The code certainly did work for me – https://prnt.sc/szz4pr. I tried to code on Avada theme just to be sure that it works without the default Dokan Theme as well.

    You should try adding priority on the hook and replace the first line of the code with this –

    add_action('woocommerce_before_add_to_cart_form', 'dokan_open_close', 1000);

    You can copy the code properly from here – https://gist.github.com/rashedripon/d77373b22b8a39e0f1e90c0127ba3041

    Thank you.

    Thread Starter ewomazino

    (@ewomazino)

    @rur165

    Many thanks for the snippet. It works now.

    Keep up the good work you do.

    Hello!
    This code was am looking.
    Dou you have other code for it?: Is possible that if the store are closed, the customer can not add to the cart?
    Thanks

    Hello @chonline507 ,

    Here is another use of the store open-close checker to hide the “add to cart” button on single product page.

    add_filter( 'woocommerce_is_purchasable', function($show_cart) {
    	global $product;
    	$seller = get_post_field('post_author', $product->get_id());
    	
    	if(dokan_is_store_open( $seller )) {
    		$show_cart = true;
    	} else {
    		$show_cart = false;
    	}
    	return $show_cart;
    	
    });

    I hope this works for your use case.

    Thank you ??

    Hello!

    Thanks!

    But i putted this code on functions.php , but don′t work, I think i am doing something wrong, could you give de code complete on github please, for I copy it on my file functions.

    Thanks

    Hello @chonline507 ,

    May I know which theme are you using? It is working in my Dokan Theme.

    This is the complete code. You may try to add the priority in the filter –

    add_filter( 'woocommerce_is_purchasable', function($show_cart) {
    	global $product;
    	$seller = get_post_field('post_author', $product->get_id());
    	
    	if(dokan_is_store_open( $seller )) {
    		$show_cart = true;
    	} else {
    		$show_cart = false;
    	}
    	return $show_cart;
    	
    }, 1000);

    If you are not sure you can a take professional developer’s help to modify the code according to your theme.

    Thank you.

    Hello!

    I use a electro theme, it is compatible with dokan.

    But this code I have to put on functions. php of child theme or en other side?

    Thanks

    Hello!

    I use this code on dokan theme, but dont work. I putted it on functions.php

    Please tell me how you do to do to put it.

    I WOULD REALLY APPRECIATE IT.

    Thanks

    Hello @chonline507 ,

    You are supposed to add this to your active theme’s functions.php file. I have tested and one my colleague also tested individually. The code works as expected. As this is a custom code solution I am unable to help much implementing it. You can contact a professional to help you implement this.

    Thank you ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Display Store Closed Or Open On Product Page’ is closed to new replies.