Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // CLASS BASE
- // Adds new order to Infusionsoft
- public function add_order($contact_id, $order_label, $payment_method, $products, $line_items) {
- wp_fusion()->crm->connect();
- $order_date = date('Ymd\TH:i:s', current_time('timestamp'));
- $infusionsoft_invoice_id = wp_fusion()->crm->app->blankOrder( $contact_id, $order_label, $order_date, 0, 0 );
- // Create each product if it doesn't exist yet
- foreach($products as $product) {
- // $product should have $product['name'], $product['id'], $product['description'], $product['sku'], $product['qty']
- $infusionsoft_product_id = $this->add_product($product);
- wp_fusion()->crm->app->addOrderItem($infusionsoft_invoice_id, $infusionsoft_product_id, 4, $product['price'], $product['qty'], $product['name'], $product['description']);
- }
- // Add each line item (not products) to the order
- foreach($line_items as $line_item) {
- wp_fusion()->crm->app->addOrderItem($infusionsoft_invoice_id, 0, $line_item['type'], $line_item['price'], 1, $line_item['title'], $line_item['description']);
- }
- $totals = (float) wp_fusion()->crm->app->amtOwed($infusionsoft_invoice_id);
- wp_fusion()->crm->app->manualPmt($infusionsoft_invoice_id, $totals, $order_date, $payment_method, $order_label, false);
- //Add Order Notes
- $jobid = wp_fusion()->crm->app->dsLoad("Invoice", $infusionsoft_invoice_id, array("JobId"));
- $jobid = (int) $jobid['JobId'];
- wp_fusion()->crm->app->dsUpdate("Job", $jobid, array('OrderType' => 'Online'));
- return $infusionsoft_invoice_id;
- }
- // Creates new PRODUCT in Infusionsoft if product doesn't exist yet
- public function add_product( $product ) {
- $infusionsoft_product_id = get_post_meta( $product['id'], 'infusionsoft_product_id', true );
- if(!empty($infusionsoft_product_id))
- return $infusionsoft_product_id;
- // DO code here to create product in Infusionsoft
- update_post_meta( $product['id'], 'infusionsoft_product_id', $infusionsoft_product_id );
- return $infusionsoft_product_id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement