Title: plugin not creating sub order in my custom function
Last modified: August 12, 2023

---

# plugin not creating sub order in my custom function

 *  Resolved [amitbond007](https://wordpress.org/support/users/amitbond007/)
 * (@amitbond007)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/plugin-not-creating-sub-order-in-my-custom-function/)
 * I am creating order in my custom function, but your plugin not creating sub order.
   I tried to add
 * if (function_exists(‘dokan_create_sub_order’)) {
   // Trigger Dokan’s sub-order
   creation functiondokan_create_sub_order($parent_order);}
 * but not going in if condition. my crate order function is below:
 * // Save sales agent Enquiry
   function save_order_data() {global $wpdb;
 *     ```wp-block-code
       // Retrieve form data
       $product_idsArr = $_POST['product'];
        $variations_idsArr = $_POST['variation'];
       $productvalidation=1;
       if(!empty($product_idsArr)){
           foreach($product_idsArr as $productId){
               if($productId==""){
                       $productvalidation=0;
               }
           }
       }else{
           $productvalidation=0;
       }
   
       $variationvalidation=1;
       if(!empty($variations_idsArr)){
           foreach($variations_idsArr as $variationId){
               if($variationId==""){
                       $variationvalidation=0;
               }
           }
       }else{
           $variationvalidation=0;
       }
   
       $userId = $_POST['users'];
       $uservalidation=1;
       if($userId==""){
            $uservalidation=0;
       }
       if($uservalidation==1 && $productvalidation==1 && $variationvalidation==1){
   
           $order = wc_create_order();
           $order->set_customer_id($userId);
           foreach ($variations_idsArr as $product_id) {
               $product = wc_get_product($product_id);
               $order->add_product($product, 1);
           }
           $order_total = $_POST["grossamount"];
           $order->set_total($order_total);
           $order->save();
           $order_id = $order_id = $order->get_id();
           $sales_agent_id = get_current_user_id();
           $current_user = wp_get_current_user();
           $sales_agent_name = $current_user->display_name;
           $providing_book = isset($_POST["providebook"]) ? 'yes' : 'no';
           if($providing_book=="yes"){
               $booksArr=$_POST["books"];
               $booksCodes=implode(",",$booksArr);
           }else{
               $booksCodes="";
           }
           //update_post_meta($order_id, 'has_sub_order', '1');
           update_post_meta($order_id, 'sales_agent_id', $sales_agent_id);
           update_post_meta($order_id, 'sales_agent_name', $sales_agent_name);
           update_post_meta($order_id, 'providing_book', $providing_book);
           update_post_meta($order_id, 'book_codes', $booksCodes);
   
   
   
           $response = array(
               'success' => true,
               'message' => $order_id
           );
   
       }else{
   
               $response = array(
                   'success' => false,
                   'message' => 'Please select user, product and variations.'
               );
   
   
       }
   
       // Return the JSON response
       wp_send_json($response);
       ```
   
 * }
   add_action(‘wp_ajax_save_order_data’, ‘save_order_data’);add_action(‘wp_ajax_nopriv_save_order_data’,‘
   save_order_data’);
 * How to work yourplugin in my function. Please help.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Tanvir Hasan](https://wordpress.org/support/users/tanvirh/)
 * (@tanvirh)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/plugin-not-creating-sub-order-in-my-custom-function/#post-16968484)
 * Hi [@amitbond007](https://wordpress.org/support/users/amitbond007/)
 * Thank you for sharing the custom codes you have created for the sub-orders. Please
   note that according to our [support policy](https://wedevs.com/support-policy/),
   we are unable to provide further assistance regarding this custom work. We recommend
   hiring a professional WordPress developer who can help you with the necessary
   customization.
 * I hope this explains the scenario.
 * Thanks!
 *  [Tanvir Hasan](https://wordpress.org/support/users/tanvirh/)
 * (@tanvirh)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/plugin-not-creating-sub-order-in-my-custom-function/#post-16981794)
 * Hi [@amitbond007](https://wordpress.org/support/users/amitbond007/)
 * As we haven’t heard back from you for a while, we’ll consider this topic resolved.
   If you encounter any further issues, please don’t hesitate to open a new topic.
 * Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘plugin not creating sub order in my custom function’ is closed to new
replies.

 * ![](https://ps.w.org/dokan-lite/assets/icon-256x256.gif?rev=3239229)
 * [Dokan: AI Powered WooCommerce Multivendor Marketplace Solution – Build Your Own Amazon, eBay, Etsy](https://wordpress.org/plugins/dokan-lite/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/dokan-lite/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/dokan-lite/)
 * [Active Topics](https://wordpress.org/support/plugin/dokan-lite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/dokan-lite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/dokan-lite/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Tanvir Hasan](https://wordpress.org/support/users/tanvirh/)
 * Last activity: [2 years, 9 months ago](https://wordpress.org/support/topic/plugin-not-creating-sub-order-in-my-custom-function/#post-16981794)
 * Status: resolved