Last active
February 7, 2022 08:03
-
-
Save rashedripon/d77373b22b8a39e0f1e90c0127ba3041 to your computer and use it in GitHub Desktop.
Dokan store open-close in single product page
This file contains hidden or 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 | |
//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 | |
} | |
} |
Hello! thanks for sharing the code. I have an issue that just appears closed all the time. What could be the problem?
Hi, @cromapc sorry that I am responding late. I have updated the code & now it should work properly.
Hi,
@rashedripon thanks! But I want to use a variable icon, so I added two icons instead of one, "toogle-on (green)" and "toogle-off (red)" for each option separately. This code will remove the trash can icon and use the variable icon along with the text.
<div class="dokan-store-open-close">
<?php if ( dokan_is_store_open( $seller_id ) ) {
echo '<i class="fad fa-toggle-on" style="--fa-primary-color: #00a800;--fa-secondary-color: white;--fa-secondary-opacity: 1.0;"></i> '. esc_attr( $store_open_notice );
} else {
echo '<i class="fad fa-toggle-off" style="--fa-primary-color: white;--fa-secondary-color: #ff0000;--fa-secondary-opacity: 1.0;"></i> '. esc_attr( $store_closed_notice );
} ?>
</div>
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
Hello! thanks for sharing the code. I have an issue that just appears closed all the time. What could be the problem?