With the WooCommerce and Dokan plugins, you have a WordPress multi-vendor eCommerce website. There may be instances where you want to base the products’ availability for purchase on the store’s opening and closing hours.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |