Wordpress (Woocommerce extension) - Create new order programmatically

后端 未结 8 1609
小蘑菇
小蘑菇 2021-01-31 11:29

I want to create a new order programmatically.

Workflow is simple: After submitting simple form, user will be created and along with that, a new order.

I managed

8条回答
  •  抹茶落季
    2021-01-31 11:52

    maybe this way..

        function insert_order_to_db($seller,$order_date){
            global $wpdb;
            $result   = $wpdb->query(
                "
                INSERT INTO `wp_posts`(`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`)
    
                VALUES (
                17188,
                $seller,
                '".date_format($order_date, 'Y-m-d H:i:s e')."',
                '".date_format($order_date, 'Y-m-d H:i:s e')."',
                'no',
                'Order –". date_format($order_date, 'F d, Y @ h:i A')."',
                'noxp',
                'wc-completed',
                'open',
                'close',
                '".uniqid( 'order_' )."',
                'order-". date_format($order_date, 'M-d-Y-hi-a')."',
                '',
                '',
                '2017-07-24',
                '2017-07-24',
                '',
                0,
                '',
                0,
                'shop_order',
                '',
                0)
    
                "
            );
            $order_id = $wpdb->insert_id;
            return $order_id;
        }
    function proccess_order_meta(){
            $date     = date_create("2017-07-24");
            $order_id = insert_order_to_db(194816,$date);
            if( is_wp_error( $order_id ) ){
                $order->errors = $order_id;
            }
            else
            {
                $order_id = 17188;
                add_post_meta($order_id, '_payment_method_title', 'پرداخت آنلاین', true);
                add_post_meta($order_id, '_order_total', 30000, true);
                add_post_meta($order_id, '_customer_user',  194816, true);
                add_post_meta($order_id, '_completed_date', date_format( $date, 'Y-m-d H:i:s e'), true);
                add_post_meta($order_id, '_paid_date', date_format( $date, 'Y-m-d H:i:s e'), true);
                add_post_meta($order_id, '_billing_email', "mavaezi46@gmail.com", true);
                add_post_meta($order_id, '_billing_first_name', "علی", true);
    
            }
    
        }
        proccess_order_meta();
    

提交回复
热议问题