Last active
February 6, 2019 17:56
-
-
Save mahbubme/be34b64c6ef67c64df9dd8a921b888b1 to your computer and use it in GitHub Desktop.
Dokan Plugin
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 | |
/* | |
* Paste this code in the theme functions.php | |
*/ | |
remove_filter( 'manage_edit-shop_order_columns', 'dokan_admin_shop_order_edit_columns', 11 ); | |
remove_action( 'manage_shop_order_posts_custom_column', 'dokan_shop_order_custom_columns', 11 ); | |
function dokan_admin_shop_order_add_shopname_column( $existing_columns ) { | |
$columns = array(); | |
$columns['cb'] = '<input type="checkbox" />'; | |
$columns['order_status'] = '<span class="status_head tips" data-tip="' . esc_attr__( 'Status', 'dokan' ) . '">' . esc_attr__( 'Status', 'dokan' ) . '</span>'; | |
$columns['order_title'] = __( 'Order', 'dokan' ); | |
$columns['order_items'] = __( 'Purchased', 'dokan' ); | |
$columns['shipping_address'] = __( 'Ship to', 'dokan' ); | |
$columns['customer_message'] = '<span class="notes_head tips" data-tip="' . esc_attr__( 'Customer Message', 'dokan' ) . '">' . esc_attr__( 'Customer Message', 'dokan' ) . '</span>'; | |
$columns['order_notes'] = '<span class="order-notes_head tips" data-tip="' . esc_attr__( 'Order Notes', 'dokan' ) . '">' . esc_attr__( 'Order Notes', 'dokan' ) . '</span>'; | |
$columns['order_date'] = __( 'Date', 'dokan' ); | |
$columns['order_total'] = __( 'Total', 'dokan' ); | |
$columns['order_actions'] = __( 'Actions', 'dokan' ); | |
$columns['seller'] = __( 'Seller', 'dokan' ); | |
$columns['shopname'] = __( 'Shop Name', 'dokan' ); | |
$columns['suborder'] = __( 'Sub Order', 'dokan' ); | |
return $columns; | |
} | |
add_filter( 'manage_edit-shop_order_columns', 'dokan_admin_shop_order_add_shopname_column', 10 ); | |
/** | |
* Adds custom column on dokan admin shop order table | |
* | |
* @global type $post | |
* @global type $woocommerce | |
* @global WC_Order $the_order | |
* @param type $col | |
*/ | |
function dokan_shop_order_add_shopname_column_data( $col ) { | |
global $post, $woocommerce, $the_order; | |
if ( empty( $the_order ) || $the_order->id != $post->ID ) { | |
$the_order = new WC_Order( $post->ID ); | |
} | |
switch ($col) { | |
case 'order_title': | |
if ($post->post_parent !== 0) { | |
echo '<strong>'; | |
echo __( 'Sub Order of', 'dokan' ); | |
printf( ' <a href="%s">#%s</a>', admin_url( 'post.php?action=edit&post=' . $post->post_parent ), $post->post_parent ); | |
echo '</strong>'; | |
} | |
break; | |
case 'suborder': | |
$has_sub = get_post_meta( $post->ID, 'has_sub_order', true ); | |
if ( $has_sub == '1' ) { | |
printf( '<a href="#" class="show-sub-orders" data-class="parent-%1$d" data-show="%2$s" data-hide="%3$s">%2$s</a>', $post->ID, __( 'Show Sub-Orders', 'dokan' ), __( 'Hide Sub-Orders', 'dokan' )); | |
} | |
break; | |
case 'seller': | |
$has_sub = get_post_meta( $post->ID, 'has_sub_order', true ); | |
if ( $has_sub != '1' ) { | |
$seller = get_user_by( 'id', $post->post_author ); | |
printf( '<a href="%s">%s</a>', admin_url( 'edit.php?post_type=shop_order&author=' . $seller->ID ), $seller->display_name ); | |
} | |
break; | |
case 'shopname': | |
if ( $has_sub != '1' ) { | |
$seller_id = $post->post_author; | |
$store_info = dokan_get_store_info( $seller_id ); | |
printf( '<a href="%s">%s</a>', admin_url( 'edit.php?post_type=shop_order&author=' . $seller->ID ), $store_info['store_name'] ); | |
} | |
break; | |
} | |
} | |
add_action( 'manage_shop_order_posts_custom_column', 'dokan_shop_order_add_shopname_column_data', 10 ); |
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 | |
// Change store thumb size in store listing page | |
add_filter( 'dokan_store_list_args', 'change_store_list_thumb_size' ); | |
function change_store_list_thumb_size( $args ) { | |
$args['image_size'] = 'full'; | |
return $args; | |
} | |
?> |
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 | |
/* | |
* Shortcode for the dokan product category widget. | |
* Paste the following code in the theme functions.php file and insert the shortcode '[dk_cat_widget' in the page. | |
*/ | |
add_shortcode( 'dk_cat_widget', 'dokan_category_widget' ); | |
?> |
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 | |
/** | |
* Enable product stock management automically for the seller. | |
* Edit the render_new_product_template function in /wedevs-dokan-plugin/classes/template-products.php. Paste the following code instead of the older function. | |
**/ | |
public function render_new_product_template( $query_vars ) { | |
if ( isset( $query_vars['new-product'] ) && !WeDevs_Dokan::init()->is_pro() ) { | |
dokan_get_template_part( 'products/new-product-single' ); | |
} | |
?> | |
<script> | |
document.getElementById("_manage_stock").checked = true | |
</script> | |
<?php | |
} | |
?> |
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 | |
/** | |
* Add the number of pending products at the admin bar | |
* Paste the following code in the theme functions.php file | |
**/ | |
function add_toolbar_pending_products($admin_bar){ | |
if ( is_admin() ) { | |
$args = array( | |
'post_type' => 'product', | |
'posts_per_page' => 12, | |
'post_status' => 'pending' | |
); | |
$loop = new WP_Query( $args ); | |
$count = 0; | |
if ( $loop->have_posts() ) { | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
$count = $count + 1; | |
endwhile; | |
} else { | |
$count = 0; | |
} | |
wp_reset_postdata(); | |
$admin_bar->add_menu( array( | |
'id' => 'woocommerce-pending-products', | |
'title' => 'Pending Products (' . $count . ')', | |
'href' => admin_url() . 'edit.php?post_status=pending&post_type=product', | |
'meta' => array( | |
'title' => __('Pending Products'), | |
), | |
)); | |
} | |
} | |
add_action('admin_bar_menu', 'add_toolbar_pending_products', 100); | |
?> |
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 | |
/* | |
* To make the "I am a seller" field selected by default paste this code in the theme functions.php | |
*/ | |
remove_action( 'register_form', 'dokan_seller_reg_form_fields' ); | |
add_action( 'register_form', 'dokan_new_seller_reg_form_fields' ); | |
function dokan_new_seller_reg_form_fields() { | |
$postdata = $_POST; | |
$role = isset( $postdata['role'] ) ? $postdata['role'] : 'seller'; | |
$role_style = ( $role == 'seller' ) ? ' style="display:block"' : ''; | |
dokan_get_template_part( 'global/seller-registration-form', '', array( | |
'postdata' => $postdata, | |
'role' => $role, | |
'role_style' => $role_style | |
) ); | |
} |
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
/** | |
* Turn off sub-order customer mail | |
* | |
* @param string $email | |
* @param WC_Order $order | |
* | |
* @return array | |
*/ | |
function dokan_wc_email_recipient_sub_order( $email, $order ) { | |
if ( $order ) { | |
if (dokan_is_sub_order( $order->ID ) ) { | |
return; | |
} | |
} | |
return $email; | |
} | |
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'dokan_wc_email_recipient_sub_order', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment