Skip to content

Instantly share code, notes, and snippets.

@rashedripon
Last active February 7, 2022 08:03
Show Gist options
  • Save rashedripon/d77373b22b8a39e0f1e90c0127ba3041 to your computer and use it in GitHub Desktop.
Save rashedripon/d77373b22b8a39e0f1e90c0127ba3041 to your computer and use it in GitHub Desktop.
Dokan store open-close in single product page
<?php
//Remove the <?php while using it in your theme's functions.php file
//Add store open-show information before single product add-to-cart button
add_action('woocommerce_before_add_to_cart_form', 'dokan_open_close', 1000);
function dokan_open_close() {
global $product;
$seller_id = get_post_field( 'post_author', $product->get_id());
$store_info = dokan_get_store_info( $seller_id );
$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( $seller_id ) ) {
echo esc_attr( $store_open_notice );
} else {
echo esc_attr( $store_closed_notice );
} ?>
</div>
<?php
}
}
@renrax
Copy link

renrax commented Feb 7, 2022

Hi @rashedripon,
Let me ask you, why duplicate lines 14 and 15? Isn't that a mistake?

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