if ($post->post_author != $seller_id) { wp_die(__('Access Denied', 'dokan')); } if (isset($_POST['update_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)); } $_regular_price = get_post_meta($post_id, '_regular_price', true); $_sale_price = get_post_meta($post_id, '_sale_price', true); $is_discount = !empty($_sale_price) ? true : false; $_sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true); $_sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true); $_sale_price_dates_from = !empty($_sale_price_dates_from) ? date_i18n('Y-m-d', $_sale_price_dates_from) : ''; $_sale_price_dates_to = !empty($_sale_price_dates_to) ? date_i18n('Y-m-d', $_sale_price_dates_to) : ''; $show_schedule = false; if (!empty($_sale_price_dates_from) && !empty($_sale_price_dates_to)) { $show_schedule = true; } $_featured = get_post_meta($post_id, '_featured', true); $_weight = get_post_meta($post_id, '_weight', true);
/** * Send email to seller once a product is published * * @param WP_Post $post * @param WP_User $seller */ function product_published($post, $seller) { $template = DOKAN_INC_DIR . '/emails/product-published.php'; ob_start(); include $template; $body = ob_get_clean(); $product = get_product($post->ID); $find = array('%seller_name%', '%title%', '%product_link%', '%product_edit_link%', '%site_name%', '%site_url%'); $replace = array($seller->display_name, $product->get_title(), get_permalink($post->ID), dokan_edit_product_url($post->ID), $this->get_from_name(), home_url()); $body = str_replace($find, $replace, $body); $subject = sprintf(__('[%s] Your product has been approved!', 'dokan'), $this->get_from_name()); $this->send($seller->user_email, $subject, $body); }
/** * Handle all the form POST submit * * @return void */ 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 of your product ...', 'dokan'); if (!$_POST) { return; } if (isset($_POST['dokan_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 = isset($_POST['post_excerpt']) ? trim($_POST['post_excerpt']) : ''; $price = floatval($_POST['_regular_price']); $featured_image = absint($_POST['feat_image_id']); $delivery_policy = trim($_POST['_delivery_policy']); $return_policy = trim($_POST['_return_policy']); $warranty_policy = trim($_POST['_warranty_policy']); $seller_policy = trim($_POST['_seller_policy']); if (empty($post_title)) { $errors[] = __('Please enter product title', 'dokan'); } if (dokan_get_option('product_category_style', 'dokan_selling', 'single') == 'single') { $product_cat = intval($_POST['product_cat']); if ($product_cat < 0) { $errors[] = __('Please select a category', 'dokan'); } } else { if (!isset($_POST['product_cat']) && empty($_POST['product_cat'])) { $errors[] = __('Please select AT LEAST ONE category', 'dokan'); } } if (isset($_POST['dokan_product_id']) && empty($_POST['dokan_product_id'])) { self::$errors = apply_filters('dokan_can_add_product', $errors); } else { self::$errors = apply_filters('dokan_can_edit_product', $errors); } if (!self::$errors) { if (isset($_POST['dokan_product_id']) && empty($_POST['dokan_product_id'])) { $product_status = dokan_get_new_post_status(); $post_data = apply_filters('dokan_insert_product_post_data', array('post_type' => 'product', 'post_status' => $product_status, 'post_title' => $post_title, 'post_content' => $post_content, 'post_excerpt' => $post_excerpt)); $product_id = wp_insert_post($post_data); } else { $post_id = (int) $_POST['dokan_product_id']; $product_info = apply_filters('dokan_update_product_post_data', 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')); $product_id = wp_update_post($product_info); } if ($product_id) { /** set images **/ if ($featured_image) { set_post_thumbnail($product_id, $featured_image); } if (isset($_POST['product_tag']) && !empty($_POST['product_tag'])) { $tags_ids = array_map('intval', (array) $_POST['product_tag']); wp_set_object_terms($product_id, $tags_ids, 'product_tag'); } /** set product category * */ if (dokan_get_option('product_category_style', 'dokan_selling', 'single') == 'single') { wp_set_object_terms($product_id, (int) $_POST['product_cat'], 'product_cat'); } else { if (isset($_POST['product_cat']) && !empty($_POST['product_cat'])) { $cat_ids = array_map('intval', (array) $_POST['product_cat']); wp_set_object_terms($product_id, $cat_ids, 'product_cat'); } } /** Set Product type by default simple */ if (isset($_POST['_create_variation']) && $_POST['_create_variation'] == 'yes') { wp_set_object_terms($product_id, 'variable', 'product_type'); } else { 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'); update_post_meta($product_id, '_delivery_policy', $delivery_policy); update_post_meta($product_id, '_return_policy', $return_policy); update_post_meta($product_id, '_warranty_policy', $warranty_policy); update_post_meta($product_id, '_seller_policy', $seller_policy); dokan_new_process_product_meta($product_id); if (isset($_POST['dokan_product_id']) && empty($_POST['dokan_product_id'])) { do_action('dokan_new_product_added', $product_id, $post_data); } if (isset($_POST['dokan_product_id']) && empty($_POST['dokan_product_id'])) { if (dokan_get_option('product_add_mail', 'dokan_general', 'on') == 'on') { Dokan_Email::init()->new_product_added($product_id, $product_status); } } wp_redirect(add_query_arg(array('message' => 'success'), dokan_edit_product_url($product_id))); exit; } } } 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']); $featured_image = absint($_POST['feat_image_id']); if (empty($post_title)) { $errors[] = __('Please enter product title', 'dokan'); } if (dokan_get_option('product_category_style', 'dokan_selling', 'single') == 'single') { $product_cat = intval($_POST['product_cat']); if ($product_cat < 0) { $errors[] = __('Please select a category', 'dokan'); } } else { if (!isset($_POST['product_cat']) && empty($_POST['product_cat'])) { $errors[] = __('Please select AT LEAST ONE category', 'dokan'); } } self::$errors = apply_filters('dokan_can_add_product', $errors); if (!self::$errors) { $product_status = dokan_get_new_post_status(); $post_data = apply_filters('dokan_insert_product_post_data', array('post_type' => 'product', 'post_status' => $product_status, '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); } if (isset($_POST['product_tag']) && !empty($_POST['product_tag'])) { $tags_ids = array_map('intval', (array) $_POST['product_tag']); wp_set_object_terms($product_id, $tags_ids, 'product_tag'); } /** set product category * */ if (dokan_get_option('product_category_style', 'dokan_selling', 'single') == 'single') { wp_set_object_terms($product_id, (int) $_POST['product_cat'], 'product_cat'); } else { if (isset($_POST['product_cat']) && !empty($_POST['product_cat'])) { $cat_ids = array_map('intval', (array) $_POST['product_cat']); wp_set_object_terms($product_id, $cat_ids, 'product_cat'); } } /** Set Product type by default simple */ 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); if (dokan_get_option('product_add_mail', 'dokan_general', 'on') == 'on') { Dokan_Email::init()->new_product_added($product_id, $product_status); } 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')) { $post_title = trim($_POST['post_title']); if (empty($post_title)) { $errors[] = __('Please enter product title', 'dokan'); } if (dokan_get_option('product_category_style', 'dokan_selling', 'single') == 'single') { $product_cat = intval($_POST['product_cat']); if ($product_cat < 0) { $errors[] = __('Please select a category', 'dokan'); } } else { if (!isset($_POST['product_cat']) && empty($_POST['product_cat'])) { $errors[] = __('Please select AT LEAST ONE category', 'dokan'); } } self::$errors = apply_filters('dokan_can_edit_product', $errors); if (!self::$errors) { $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 tags */ if (isset($_POST['product_tag'])) { $tags_ids = array_map('intval', (array) $_POST['product_tag']); } else { $tags_ids = array(); } wp_set_object_terms($post_id, $tags_ids, 'product_tag'); /** set product category * */ if (dokan_get_option('product_category_style', 'dokan_selling', 'single') == 'single') { wp_set_object_terms($post_id, (int) $_POST['product_cat'], 'product_cat'); } else { if (isset($_POST['product_cat']) && !empty($_POST['product_cat'])) { $cat_ids = array_map('intval', (array) $_POST['product_cat']); wp_set_object_terms($post_id, $cat_ids, 'product_cat'); } } wp_set_object_terms($post_id, 'simple', 'product_type'); /** Process all variation products meta */ 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; } } }
echo $product->get_image(); ?> </a> </td> <td> <p><a href="<?php echo dokan_edit_product_url($post->ID); ?> "><?php echo $product->get_title(); ?> </a></p> <div class="row-actions"> <span class="edit"><a href="<?php echo dokan_edit_product_url($post->ID); ?> "><?php _e('Edit', 'dokan'); ?> </a> | </span> <span class="delete"><a onclick="return confirm('Are you sure?');" href="<?php echo wp_nonce_url(add_query_arg(array('action' => 'dokan-delete-product', 'product_id' => $post->ID), dokan_get_navigation_url('products')), 'dokan-delete-product'); ?> "><?php _e('Delete Permanently', 'dokan'); ?> </a> | </span> <span class="view"><a href="<?php echo get_permalink($product->ID); ?>
function handle_all_submit() { $errors = array(); self::$product_cat = -1; //self::$post_content = __( 'Details about your product...', 'dokan' ); self::$post_content = __('', 'dokan'); if (!$_POST) { return; } if (isset($_POST['add_product'])) { $post_title = trim($_POST['post_title']); $post_content = trim($_POST['post_content']); $post_excerpt = trim($_POST['post_excerpt']); $mrp = floatval($_POST['mrp']); $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) { $product_status = dokan_get_new_post_status(); $post_data = apply_filters('dokan_insert_product_post_data', array('post_type' => 'product', 'post_status' => $product_status, '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, '_list_price_mrp', $mrp); update_post_meta($product_id, '_sale_price', ''); update_post_meta($product_id, '_price', $price); update_post_meta($product_id, '_visibility', 'visible'); $sell = array('sell_in' => '', 'state' => '', 'city' => ''); update_post_meta($product_id, 'sell_in', $sell); do_action('dokan_new_product_added', $product_id, $post_data); Dokan_Email::init()->new_product_added($product_id, $product_status); wp_redirect(dokan_edit_product_url($product_id)); } } } if (isset($_GET['product_id'])) { $post_id = intval($_GET['product_id']); } else { global $post, $product; $post_id = $post->ID; } if (isset($_POST['update_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)); } dokan_delete_product_handler(); // Coupon functionality $dokan_template_coupons = Dokan_Template_Coupons::init(); self::$validated = $dokan_template_coupons->validate(); if (!is_wp_error(self::$validated)) { $dokan_template_coupons->coupons_create(); } $dokan_template_coupons->coupun_delete(); // Withdraw functionality $dokan_withdraw = Dokan_Template_Withdraw::init(); self::$validate = $dokan_withdraw->validate(); if (self::$validate !== false && !is_wp_error(self::$validate)) { $dokan_withdraw->insert_withdraw_info(); } $dokan_withdraw->cancel_pending(); }
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; } }
$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, $product_status); wp_redirect(dokan_edit_product_url($product_id)); } } } get_header(); dokan_frontend_dashboard_scripts(); ?> <?php dokan_get_template(dirname(__FILE__) . '/dashboard-nav.php', array('active_menu' => 'product')); ?> <div id="primary" class="content-area col-md-9"> <div id="content" class="site-content" role="main"> <?php