Example #1
0
/**
 * If the current user is not seller, redirect to homepage
 *
 * @param string $redirect
 */
function dokan_redirect_if_not_seller($redirect = '')
{
    if (!dokan_is_user_seller(get_current_user_id())) {
        $redirect = empty($redirect) ? home_url('/') : $redirect;
        wp_redirect($redirect);
        exit;
    }
}
Example #2
0
 /**
  * Include store template
  *
  * @param type $template
  * @return string
  */
 function store_template($template)
 {
     $store_name = get_query_var('store');
     if (!empty($store_name)) {
         $store_user = get_user_by('slug', $store_name);
         // no user found
         if (!$store_user) {
             return get_404_template();
         }
         // check if the user is seller
         if (!dokan_is_user_seller($store_user->ID)) {
             return get_404_template();
         }
         $templates = array("store-{$store_name}.php", 'store.php');
         return get_query_template('store', $templates);
     }
     return $template;
 }
Example #3
0
function tokopress_dokan_quicknav_account()
{
    if (!is_user_logged_in()) {
        return;
    }
    global $current_user;
    $user_id = $current_user->ID;
    if (!dokan_is_user_seller($user_id)) {
        return;
    }
    // $nav_urls = dokan_get_dashboard_nav();
    // foreach ($nav_urls as $key => $item) {
    //     printf( '<li><a href="%s">%s %s</a></li>', $item['url'], $item['title'], $item['icon'] );
    // }
    $title = __('Dashboard', 'dokan');
    $icon = '<i class="fa fa-tachometer"></i>';
    $url = dokan_get_navigation_url();
    printf('<li><a href="%s">%s %s</a></li>', $url, $title, $icon);
}
 /**
  * Save settings via ajax
  *
  * @return void
  */
 function ajax_settings()
 {
     if (!dokan_is_user_seller(get_current_user_id())) {
         wp_send_json_error(__('Are you cheating?', 'dokan'));
     }
     $_POST['dokan_update_profile'] = '';
     switch ($_POST['form_id']) {
         case 'profile-form':
             if (!wp_verify_nonce($_POST['_wpnonce'], 'dokan_profile_settings_nonce')) {
                 wp_send_json_error(__('Are you cheating?', 'dokan'));
             }
             $ajax_validate = $this->profile_validate();
             break;
         case 'store-form':
             if (!wp_verify_nonce($_POST['_wpnonce'], 'dokan_store_settings_nonce')) {
                 wp_send_json_error(__('Are you cheating?', 'dokan'));
             }
             $ajax_validate = $this->store_validate();
             break;
         case 'payment-form':
             if (!wp_verify_nonce($_POST['_wpnonce'], 'dokan_payment_settings_nonce')) {
                 wp_send_json_error(__('Are you cheating?', 'dokan'));
             }
             $ajax_validate = $this->payment_validate();
             break;
     }
     if (is_wp_error($ajax_validate)) {
         wp_send_json_error($ajax_validate->errors);
     }
     // we are good to go
     $save_data = $this->insert_settings_info();
     $progress_bar = dokan_get_profile_progressbar();
     $success_msg = __('Your information has been saved successfully', 'dokan');
     $data = array('progress' => $progress_bar, 'msg' => $success_msg);
     wp_send_json_success($data);
 }
Example #5
0
    /**
     * User top navigation menu
     *
     * @return void
     */
    function dokan_header_user_menu()
    {
        ?>
    <ul class="nav navbar-nav navbar-right">
        <li>
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php 
        printf(__('Cart %s', 'dokan'), '<span class="dokan-cart-amount-top">(' . WC()->cart->get_cart_total() . ')</span>');
        ?>
 <b class="caret"></b></a>

            <ul class="dropdown-menu">
                <li>
                    <div class="widget_shopping_cart_content"></div>
                </li>
            </ul>
        </li>

        <?php 
        if (is_user_logged_in()) {
            ?>

            <?php 
            global $current_user;
            $user_id = $current_user->ID;
            if (dokan_is_user_seller($user_id)) {
                ?>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php 
                _e('Seller Dashboard', 'dokan');
                ?>
 <b class="caret"></b></a>

                    <ul class="dropdown-menu">
                        <li><a href="<?php 
                echo dokan_get_store_url($user_id);
                ?>
" target="_blank"><?php 
                _e('Visit your store', 'dokan');
                ?>
 <i class="fa fa-external-link"></i></a></li>
                        <li class="divider"></li>
                        <?php 
                $nav_urls = dokan_get_dashboard_nav();
                foreach ($nav_urls as $key => $item) {
                    printf('<li><a href="%s">%s &nbsp;%s</a></li>', $item['url'], $item['icon'], $item['title']);
                }
                ?>
                    </ul>
                </li>
            <?php 
            }
            ?>

            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php 
            echo esc_html($current_user->display_name);
            ?>
 <b class="caret"></b></a>
                <ul class="dropdown-menu">
                    <li><a href="<?php 
            echo dokan_get_page_url('my_orders');
            ?>
"><?php 
            _e('My Orders', 'dokan');
            ?>
</a></li>
                    <li><a href="<?php 
            echo dokan_get_page_url('myaccount', 'woocommerce');
            ?>
"><?php 
            _e('My Account', 'dokan');
            ?>
</a></li>
                    <li><a href="<?php 
            echo wc_customer_edit_account_url();
            ?>
"><?php 
            _e('Edit Account', 'dokan');
            ?>
</a></li>
                    <li class="divider"></li>
                    <li><a href="<?php 
            echo wc_get_endpoint_url('edit-address', 'billing', get_permalink(wc_get_page_id('myaccount')));
            ?>
"><?php 
            _e('Billing Address', 'dokan');
            ?>
</a></li>
                    <li><a href="<?php 
            echo wc_get_endpoint_url('edit-address', 'shipping', get_permalink(wc_get_page_id('myaccount')));
            ?>
"><?php 
            _e('Shipping Address', 'dokan');
            ?>
</a></li>
                </ul>
            </li>

            <li><?php 
            wp_loginout(home_url());
            ?>
</li>

        <?php 
        } else {
            ?>
            <li><a href="<?php 
            echo dokan_get_page_url('myaccount', 'woocommerce');
            ?>
"><?php 
            _e('Log in', 'dokan');
            ?>
</a></li>
            <li><a href="<?php 
            echo dokan_get_page_url('myaccount', 'woocommerce');
            ?>
"><?php 
            _e('Sign Up', 'dokan');
            ?>
</a></li>
        <?php 
        }
        ?>
    </ul>
    <?php 
    }
 /**
  * Handle delete product link
  *
  * @return void
  */
 function handle_delete_product()
 {
     if (!is_user_logged_in()) {
         return;
     }
     if (!dokan_is_user_seller(get_current_user_id())) {
         return;
     }
     dokan_delete_product_handler();
 }
 /**
  *  Handle Shipping post submit
  *
  *  @since  2.0
  *  @return void
  */
 function handle_shipping()
 {
     if (!is_user_logged_in()) {
         return;
     }
     if (!dokan_is_user_seller(get_current_user_id())) {
         return;
     }
     if (isset($_POST['dokan_update_shipping_options']) && wp_verify_nonce($_POST['dokan_shipping_form_field_nonce'], 'dokan_shipping_form_field')) {
         $user_id = get_current_user_id();
         $s_rates = array();
         $rates = array();
         if (isset($_POST['dps_enable_shipping'])) {
             update_user_meta($user_id, '_dps_shipping_enable', $_POST['dps_enable_shipping']);
         }
         if (isset($_POST['dokan_shipping_type'])) {
             update_user_meta($user_id, '_dokan_shipping_type', $_POST['dokan_shipping_type']);
         }
         if (isset($_POST['dps_shipping_type_price'])) {
             update_user_meta($user_id, '_dps_shipping_type_price', $_POST['dps_shipping_type_price']);
         }
         if (isset($_POST['dps_additional_product'])) {
             update_user_meta($user_id, '_dps_additional_product', $_POST['dps_additional_product']);
         }
         if (isset($_POST['dps_additional_qty'])) {
             update_user_meta($user_id, '_dps_additional_qty', $_POST['dps_additional_qty']);
         }
         if (isset($_POST['dps_pt'])) {
             update_user_meta($user_id, '_dps_pt', $_POST['dps_pt']);
         }
         if (isset($_POST['dps_ship_policy'])) {
             update_user_meta($user_id, '_dps_ship_policy', $_POST['dps_ship_policy']);
         }
         if (isset($_POST['dps_refund_policy'])) {
             update_user_meta($user_id, '_dps_refund_policy', $_POST['dps_refund_policy']);
         }
         if (isset($_POST['dps_form_location'])) {
             update_user_meta($user_id, '_dps_form_location', $_POST['dps_form_location']);
         }
         if (isset($_POST['dps_country_to'])) {
             foreach ($_POST['dps_country_to'] as $key => $value) {
                 $country = $value;
                 $c_price = floatval($_POST['dps_country_to_price'][$key]);
                 if (!$c_price && empty($c_price)) {
                     $c_price = 0;
                 }
                 if (!empty($value)) {
                     $rates[$country] = $c_price;
                 }
             }
         }
         update_user_meta($user_id, '_dps_country_rates', $rates);
         if (isset($_POST['dps_state_to'])) {
             foreach ($_POST['dps_state_to'] as $country_code => $states) {
                 foreach ($states as $key_val => $name) {
                     $country_c = $country_code;
                     $state_code = $name;
                     $s_price = floatval($_POST['dps_state_to_price'][$country_c][$key_val]);
                     if (!$s_price || empty($s_price)) {
                         $s_price = 0;
                     }
                     if (!empty($name)) {
                         $s_rates[$country_c][$state_code] = $s_price;
                     }
                 }
             }
         }
         update_user_meta($user_id, '_dps_state_rates', $s_rates);
         $shipping_url = dokan_get_navigation_url('settings/shipping');
         wp_redirect(add_query_arg(array('message' => 'shipping_saved'), $shipping_url));
         exit;
     }
 }
Example #8
0
 /**
  * Handle the coupons submission
  *
  * @return void
  */
 function handle_coupons()
 {
     if (!is_user_logged_in()) {
         return;
     }
     if (!dokan_is_user_seller(get_current_user_id())) {
         return;
     }
     // Coupon functionality
     self::$validated = $this->validate();
     if (!is_wp_error(self::$validated)) {
         $this->coupons_create();
     }
     $this->coupun_delete();
 }
Example #9
0
 /**
  * Include store template
  *
  * @param type    $template
  * @return string
  */
 function store_template($template)
 {
     $store_name = get_query_var('store');
     if (!$this->is_woo_installed()) {
         return $template;
     }
     if (!empty($store_name)) {
         $store_user = get_user_by('slug', $store_name);
         // no user found
         if (!$store_user) {
             return get_404_template();
         }
         // check if the user is seller
         if (!dokan_is_user_seller($store_user->ID)) {
             return get_404_template();
         }
         return dokan_locate_template('store.php');
     }
     return $template;
 }
Example #10
0
?>
 <b class="caret"></b></a>

        <ul class="dropdown-menu">
            <li>
                <div class="widget_shopping_cart_content"></div>
            </li>
        </ul>
    </li>

    <?php 
if (is_user_logged_in()) {
    ?>

        <?php 
    if (dokan_is_user_seller($user_id)) {
        ?>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php 
        _e('Seller Dashboard', 'dokan');
        ?>
 <b class="caret"></b></a>

                <ul class="dropdown-menu">
                    <li><a href="<?php 
        echo dokan_get_store_url($user_id);
        ?>
" target="_blank"><?php 
        _e('Visit your store', 'dokan');
        ?>
 <i class="fa fa-external-link"></i></a></li>
Example #11
0
 function handle_all_submit()
 {
     if (!is_user_logged_in()) {
         return;
     }
     if (!dokan_is_user_seller(get_current_user_id())) {
         return;
     }
     $errors = array();
     self::$product_cat = -1;
     self::$post_content = __('Details about your product...', 'dokan');
     if (!$_POST) {
         return;
     }
     if (isset($_POST['add_product']) && wp_verify_nonce($_POST['dokan_add_new_product_nonce'], 'dokan_add_new_product')) {
         $post_title = trim($_POST['post_title']);
         $post_content = trim($_POST['post_content']);
         $post_excerpt = trim($_POST['post_excerpt']);
         $price = floatval($_POST['price']);
         $product_cat = intval($_POST['product_cat']);
         $featured_image = absint($_POST['feat_image_id']);
         if (empty($post_title)) {
             $errors[] = __('Please enter product title', 'dokan');
         }
         if ($product_cat < 0) {
             $errors[] = __('Please select a category', 'dokan');
         }
         self::$errors = apply_filters('dokan_can_add_product', $errors);
         if (!self::$errors) {
             $post_data = apply_filters('dokan_insert_product_post_data', array('post_type' => 'product', 'post_status' => 'publish', 'post_title' => $post_title, 'post_content' => $post_content, 'post_excerpt' => $post_excerpt));
             $product_id = wp_insert_post($post_data);
             if ($product_id) {
                 /** set images **/
                 if ($featured_image) {
                     set_post_thumbnail($product_id, $featured_image);
                 }
                 /** set product category * */
                 wp_set_object_terms($product_id, (int) $_POST['product_cat'], 'product_cat');
                 wp_set_object_terms($product_id, 'simple', 'product_type');
                 update_post_meta($product_id, '_regular_price', $price);
                 update_post_meta($product_id, '_sale_price', '');
                 update_post_meta($product_id, '_price', $price);
                 update_post_meta($product_id, '_visibility', 'visible');
                 do_action('dokan_new_product_added', $product_id, $post_data);
                 Dokan_Email::init()->new_product_added($product_id, 'publish');
                 wp_redirect(dokan_edit_product_url($product_id));
                 exit;
             }
         }
     }
     if (isset($_GET['product_id'])) {
         $post_id = intval($_GET['product_id']);
     } else {
         global $post, $product;
         if (!empty($post)) {
             $post_id = $post->ID;
         }
     }
     if (isset($_POST['update_product']) && wp_verify_nonce($_POST['dokan_edit_product_nonce'], 'dokan_edit_product')) {
         $product_info = array('ID' => $post_id, 'post_title' => sanitize_text_field($_POST['post_title']), 'post_content' => $_POST['post_content'], 'post_excerpt' => $_POST['post_excerpt'], 'post_status' => isset($_POST['post_status']) ? $_POST['post_status'] : 'pending', 'comment_status' => isset($_POST['_enable_reviews']) ? 'open' : 'closed');
         wp_update_post($product_info);
         /** set product category * */
         wp_set_object_terms($post_id, (int) $_POST['product_cat'], 'product_cat');
         wp_set_object_terms($post_id, 'simple', 'product_type');
         dokan_process_product_meta($post_id);
         /** set images **/
         $featured_image = absint($_POST['feat_image_id']);
         if ($featured_image) {
             set_post_thumbnail($post_id, $featured_image);
         }
         $edit_url = dokan_edit_product_url($post_id);
         wp_redirect(add_query_arg(array('message' => 'success'), $edit_url));
         exit;
     }
 }
 /**
  * Export user orders to CSV format
  *
  * @since 1.4
  *
  * @return void
  */
 function handle_order_export()
 {
     if (!is_user_logged_in()) {
         return;
     }
     if (!dokan_is_user_seller(get_current_user_id())) {
         return;
     }
     if (isset($_POST['dokan_order_export_all'])) {
         $filename = "Orders-" . time();
         header("Content-Type: application/csv; charset=" . get_option('blog_charset'));
         header("Content-Disposition: attachment; filename={$filename}.csv");
         $headers = array('order_id' => __('Order No', 'dokan'), 'order_items' => __('Order Items', 'dokan'), 'order_shipping' => __('Shipping method', 'dokan'), 'order_shipping_cost' => __('Shipping Cost', 'dokan'), 'order_payment_method' => __('Payment method', 'dokan'), 'order_total' => __('Order Total', 'dokan'), 'order_status' => __('Order Status', 'dokan'), 'order_date' => __('Order Date', 'dokan'), 'customer_name' => __('Customer Name', 'dokan'), 'customer_email' => __('Customer Email', 'dokan'), 'customer_phone' => __('Customer Phone', 'dokan'), 'customer_ip' => __('Customer IP', 'dokan'));
         foreach ((array) $headers as $label) {
             echo $label . ', ';
         }
         echo "\r\n";
         $user_orders = dokan_get_seller_orders(get_current_user_id(), 'all', NULL, 10000000, 0);
         $statuses = wc_get_order_statuses();
         $results = array();
         foreach ($user_orders as $order) {
             $the_order = new WC_Order($order->order_id);
             $customer = get_post_meta($order->order_id, '_customer_user', true);
             if ($customer) {
                 $customer_details = get_user_by('id', $customer);
                 $customer_name = $customer_details->user_login;
                 $customer_email = esc_html(get_post_meta($order->order_id, '_billing_email', true));
                 $customer_phone = esc_html(get_post_meta($order->order_id, '_billing_phone', true));
                 $customer_ip = esc_html(get_post_meta($order->order_id, '_customer_ip_address', true));
             } else {
                 $customer_name = get_post_meta($order->id, '_billing_first_name', true) . ' ' . get_post_meta($order->id, '_billing_last_name', true) . '(Guest)';
                 $customer_email = esc_html(get_post_meta($order->order_id, '_billing_email', true));
                 $customer_phone = esc_html(get_post_meta($order->order_id, '_billing_phone', true));
                 $customer_ip = esc_html(get_post_meta($order->order_id, '_customer_ip_address', true));
             }
             $results = array('order_id' => $order->order_id, 'order_items' => dokan_get_product_list_by_order($the_order, ';'), 'order_shipping' => $the_order->get_shipping_method(), 'order_shipping_cost' => $the_order->get_total_shipping(), 'order_payment_method' => get_post_meta($order->order_id, '_payment_method_title', true), 'order_total' => $the_order->get_total(), 'order_status' => $statuses[$the_order->post_status], 'order_date' => $the_order->order_date, 'customer_name' => $customer_name, 'customer_email' => $customer_email, 'customer_phone' => $customer_phone, 'customer_ip' => $customer_ip);
             foreach ($results as $csv_key => $csv_val) {
                 echo $csv_val . ', ';
             }
             echo "\r\n";
         }
         exit;
     }
     if (isset($_POST['dokan_order_export_filtered'])) {
         $filename = "Orders-" . time();
         header("Content-Type: application/csv; charset=" . get_option('blog_charset'));
         header("Content-Disposition: attachment; filename={$filename}.csv");
         $headers = array('order_id' => __('Order No', 'dokan'), 'order_items' => __('Order Items', 'dokan'), 'order_shipping' => __('Shipping method', 'dokan'), 'order_shipping_cost' => __('Shipping Cost', 'dokan'), 'order_payment_method' => __('Payment method', 'dokan'), 'order_total' => __('Order Total', 'dokan'), 'order_status' => __('Order Status', 'dokan'), 'order_date' => __('Order Date', 'dokan'), 'customer_name' => __('Customer Name', 'dokan'), 'customer_email' => __('Customer Email', 'dokan'), 'customer_phone' => __('Customer Phone', 'dokan'), 'customer_ip' => __('Customer IP', 'dokan'));
         foreach ((array) $headers as $label) {
             echo $label . ', ';
         }
         echo "\r\n";
         $order_date = isset($_POST['order_date']) ? $_POST['order_date'] : NULL;
         $order_status = isset($_POST['order_status']) ? $_POST['order_status'] : 'all';
         $user_orders = dokan_get_seller_orders(get_current_user_id(), $order_status, $order_date, 10000000, 0);
         $statuses = wc_get_order_statuses();
         $results = array();
         foreach ($user_orders as $order) {
             $the_order = new WC_Order($order->order_id);
             $customer = get_post_meta($order->order_id, '_customer_user', true);
             if ($customer) {
                 $customer_details = get_user_by('id', $customer);
                 $customer_name = $customer_details->user_login;
                 $customer_email = esc_html(get_post_meta($order->order_id, '_billing_email', true));
                 $customer_phone = esc_html(get_post_meta($order->order_id, '_billing_phone', true));
                 $customer_ip = esc_html(get_post_meta($order->order_id, '_customer_ip_address', true));
             } else {
                 $customer_name = get_post_meta($order->id, '_billing_first_name', true) . ' ' . get_post_meta($order->id, '_billing_last_name', true) . '(Guest)';
                 $customer_email = esc_html(get_post_meta($order->order_id, '_billing_email', true));
                 $customer_phone = esc_html(get_post_meta($order->order_id, '_billing_phone', true));
                 $customer_ip = esc_html(get_post_meta($order->order_id, '_customer_ip_address', true));
             }
             $results = array('order_id' => $order->order_id, 'order_items' => dokan_get_product_list_by_order($the_order), 'order_shipping' => $the_order->get_shipping_method(), 'order_shipping_cost' => $the_order->get_total_shipping(), 'order_payment_method' => get_post_meta($order->order_id, '_payment_method_title', true), 'order_total' => $the_order->get_total(), 'order_status' => $statuses[$the_order->post_status], 'order_date' => $the_order->order_date, 'customer_name' => $customer_name, 'customer_email' => $customer_email, 'customer_phone' => $customer_phone, 'customer_ip' => $customer_ip);
             foreach ($results as $csv_key => $csv_val) {
                 echo $csv_val . ', ';
             }
             echo "\r\n";
         }
         exit;
     }
 }