Skip to content

Instantly share code, notes, and snippets.

@nayemDevs
Created December 10, 2020 09:20
Show Gist options
  • Save nayemDevs/d9d2d43e26fe7b819b7c9ffeb5fad158 to your computer and use it in GitHub Desktop.
Save nayemDevs/d9d2d43e26fe7b819b7c9ffeb5fad158 to your computer and use it in GitHub Desktop.
Show notice on vendor store & single product page
/* Store notice field seller settings */
add_filter( 'dokan_settings_form_bottom', 'extra_fields', 10, 2);
function extra_fields( $current_user, $profile_info ){
$booth_news= get_user_meta( $current_user, 'booth_news', true );
?>
<div class="gregcustom dokan-form-group">
<label class="dokan-w3 dokan-control-label" for="setting_address">
<?php _e( 'Store Notice', 'dokan' ); ?>
</label>
<div class="dokan-w8 dokan-text-left">
<?php
$booth_news_args = array(
'editor_height' => 200,
'media_buttons' => true,
'teeny' => true,
'quicktags' => false
);
wp_editor( $booth_news, 'booth_news', $booth_news_args );
?>
</div>
<?php
}
/* Saving the booth news field */
add_action( 'dokan_store_profile_saved','save_extra_fields', 10 );
function save_extra_fields( $store_id ) {
if ( ! $store_id ) {
return;
}
if ( ! isset( $_POST['booth_news'] ) ) {
return;
}
update_user_meta( $store_id, 'booth_news', $_POST['booth_news'] );
}
/*Showing extra field data on the store page*/
add_action( 'dokan_store_profile_frame_after','custom_side_bar',10,2);
function custom_side_bar( $store_user, $store_info ){
$booth_news = get_user_meta( $store_user->ID, 'booth_news', true );
?>
<?php if ( !empty( $booth_news ) ) { ?>
<div class="dokan-store-sidebar">
<aside class="widget">
<h3 class="widget-title"><?php _e( 'Notice', 'dokan' ); ?></h3>
<?php echo wpautop( $booth_news ); ?>
</aside>
</div>
<?php } ?>
<?php
}
/*Show notice on single product page*/
add_action( 'woocommerce_single_product_summary', 'booth_news_notice', 11 );
function booth_news_notice() {
global $product;
$seller = get_post_field( 'post_author', $product->get_id() );
$author = get_user_by( 'id', $seller );
$booth_news = get_user_meta( $author->ID, 'booth_news', true );
if ( ! empty( $booth_news ) ) { ?>
<div class="details">
<aside class="widget">
<h3 class="widget-title"><?php _e( 'Notice', 'dokan' ); ?></h3>
<?php echo wpautop( $booth_news ); ?>
</aside>
</div>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment