Skip to content

Instantly share code, notes, and snippets.

@mi5t4n
Last active April 26, 2022 15:57
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mi5t4n/21bc457212e5edc55e23f234b082d2b0 to your computer and use it in GitHub Desktop.
Save mi5t4n/21bc457212e5edc55e23f234b082d2b0 to your computer and use it in GitHub Desktop.
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 );
@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