• Resolved amitbond007

    (@amitbond007)


    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 function
    dokan_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;

    // 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)
  • Hi @amitbond007

    Thank you for sharing the custom codes you have created for the sub-orders. Please note that according to our 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!

    Hi @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.