Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make product purchasable based on the vendor opening and closing time in dokan plugin.
<?php
/**
* Hide or display add to cart button based on opening hours.
*/
function prefix_woocommerce_is_purchasable( $is_purchasable, $product ) {
// Get the store id.
$store_id = get_post_field( 'post_author', $product->get_id() );
// Get the store info.
$store_info = dokan_get_store_info( $store_id );
// Get the store time enabled or not.
$is_dokan_store_time_enabled = $store_info['dokan_store_time_enabled'];
// If the store time is enabled, check whether the store is open or not.
// Else the store is open.
if ( 'yes' === $is_dokan_store_time_enabled ) {
$is_purchasable = dokan_is_store_open( $store_id );
} else {
$is_purchasable = true;
}
return $is_purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'prefix_woocommerce_is_purchasable', 10, 2 );
@treskoco
Copy link

treskoco commented Jun 27, 2020

Hi Sagar Tamang,

Is there any way to use this code for disabling a specific shipping method? In an example given, if i want to use one "flat rate" method for the same delivery and if the store closes, i want this method to not appear. If you can give me a hand on this problem it would be much appreciated, either way, thanks for the code as it is.

@cromapc
Copy link

cromapc commented Dec 24, 2020

Hello! Could this code be put only for some categories of stores?

@mi5t4n
Copy link
Author

mi5t4n commented Dec 25, 2020

@cromapc
yes, you can but we need to tweak the code a little bit.

@renrax
Copy link

renrax commented Jan 26, 2022

Hello @mi5t4n ,
Sorry, do you happen to know how to apply $is_purchasable for docan live chat button? I can't find a solution anywhere on how to return the live chat button if the woocommerce_is_purchasable filter is applied to the item.

@mi5t4n
Copy link
Author

mi5t4n commented Jan 27, 2022

@renrax I think you can use $product->is_purchasable() inside the wp_enqueue_scripts hook load conditionally load the live chat button.

@renrax
Copy link

renrax commented Jan 27, 2022

@mi5t4n
Thanks, I tried it, but it didn't work, maybe not enough experience. So I just changed in the core of the plugin module

// chat button on product page
        add_action( 'woocommerce_after_add_to_cart_button', [ $this, 'render_live_chat_button_product_page' ] );

on

// chat button on product page
        add_action( 'woocommerce_single_product_summary', [ $this, 'render_live_chat_button_product_page' ], 100 );

It's tough, but I couldn't do it any other way. In any case, thanks for the tip.

@mi5t4n
Copy link
Author

mi5t4n commented Jan 27, 2022

@renrax Glad to help. Let me know, if you need help with anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment