How To Send WooCommerce Orders & Invoices By Fax in 2018

How To Send WooCommerce Orders & Invoices By Fax in 2018

Recently, one of our ecommerce clients requested that WooCommerce orders be sent to their analog fax machine. It made sense for them, a busy restaurant who wants to pick up orders off of the fax as they come in real-time. Searching Google we found one seemingly broken plugin and one reddit post suggesting the solution of signing up for a virtual fax machine (think TrustFax or eFax) and then forwarding to the clients physical fax line. 

Nextiva's $150 faxbridge, annual pricing & omg that layout!

We quickly ran into some issues going the email-to-fax method. We found Nextiva to be one of the cheapest options for virtual faxes, but after signing up, it was discovered that you’d need to purchase a $150.00 Fax Bridge device in order for your physical fax machine to receive ones sent to your virtual fax machine. (What?!) As for TrustFax and other “eFaxes”, we found that you’d need to spend around $120 to qualify for the $10.89/mo package, allowing for 500 faxes per month (ouch). 

When we did get this method to finally work via TrustFax, we noticed that the resulting fax didn’t look anything like the email. To put it simply, it looked awful.

Solution: A WORDPRESS HOOK, A FREE PDF PLUGIN & TWILLIO

After some additional searching we found that Twillio is the least expensive option. Loading your account with $20 will allow you to send about 1,000 faxes and credits don’t expire month-to-month. 

To start, signup for a Twilio account and download the Twillio PHP Helper library to your theme’s main folder (i.e. /var/www/html/mysite.com/public_html/wp-content/themes/MYTHEME/twilio_php_master). Then, modify your functions.php file and add the following 2 lines after <?php 

require __DIR__ . ‘/twilio-php-master/Twilio/autoload.php’;

use Twilio\Rest\Client;

Now, download the WooCommerce PDF Invoice Packaging Slips plugin and install it to your wordpress. After it’s installed, add the following hook in your theme’s functions.php replacing information in red with your own.

add_action(‘woocommerce_thankyou’, ‘fax_woocommerce_order’, 10, 1);

function fax_woocommerce_order( $order_id ) {

    if ( ! $order_id )

        return;

        // Twilio account credentials

        $sid = AC282xxxxxxxxxxxxxxxxxx;

        $token = cdd57xxxxxxxxxxxxxxxxxxxx;

        $twilio = new Client($sid, $token);

        // Getting an instance of the order object

        $order = wc_get_order( $order_id );

        // Get invoice from ‘WooCommerce PDF Invoice Packaging Slips’ plugin

        $invoice = wcpdf_get_invoice($order);

        $pdf_data = $invoice->get_pdf();

        $filename = $invoice->get_filename();

        $upload_dir = wp_upload_dir();

        $pdf_path = $upload_dir[‘basedir’] . ‘/wpo_wcpdf/attachments/’ .$filename;

        file_put_contents ( $pdf_path, $pdf_data );

        $pdf_file = https://eztoeat.com/wp-content/uploads/wpo_wcpdf/attachments/.$filename;

        $fax = $twilio->fax->v1->faxes->create(+1814XXXXXXX,$pdf_file,array(‘from’ => +1720XXXXXX));

}

$sid – Get your account ID on Twilio’s dashboard
$token – Get your account token in the same place
$pdf_file – Replace with your website so Twilio can access your order PDF via this url
$fax – first phone number is the number to send to and the second number is your twilio verified phone number.

Take note that the hook is placed on the thank you page. You can change this to after payment confirmation or add any other type of conditional logic in your hook before sending the fax. Here is a fax received via this method.

Keystone Web Studios

A Pennsylvania based IT consulting firm specializing in Wordpress & custom framework website / application development, ecommerce platforms, native mobile application development, SEO/SEM services, digital marketing management & technical support. Call us anytime! 855-942-0303

Leave a Reply

Close Menu

Technologies We Use

Front-End Technologies are responsible for the look and the operation of your website or application. We use technologies that are stable, widely adopted and have large community support behind them. They include:

  • HTML5 – The latest version of the Hypertext Markup Language. The base code for all web pages.
  • CSS3 – A language and set of rules for styling assets and web content on a website.
  • Bootstrap 4 – A powerful front-end framework developed by Twitter that allows developers to include web components in their applications easily.
  • Material UI – Another powerful front-end framework for React that mimics Google’s Material Design look.
  • jQuery / JavaScript – A client-side processing language for controlling front-end functions and managing data between the front and back-end of websites and applications.

Back-End Technologies remain on a server and are responsible for things like user authentication, some website functionality, data searches and data storage. Technologies that we use are stable, widely adopted and have large community support behind them. They include:

  • Laravel PHP Framework – A popular MVC (model-view-controller) PHP framework used in the development of websites and APIs for mobile development.
  • MySQL – A open source relational database management platform (Structured Query Language). 
  • NGINX – A fast and stable web server / load balancer for websites and APIs.
  • Ubuntu Server – A popular server architecture great for running websites, databases and APIs

Open Source Technologies are community written software projects that are available for free on the internet and can be modified to better fit a company’s needs. Should you need, we can adjust any open source system to meet the requirements of your business.

  • Wordpress – Content management system used to build websites and web applications.
  • WooCommerce – Comprehensive ECommerce plugin for Wordpress.
  • Magento – Standalone eCommerce platform written in PHP.
  • SuiteCRM – Customer relationship manager with built in email marketing capabilities.
  • OpenProject – Team based project management software. 

Front-End Technologies are responsible for the look and the operation of your website or application. We use technologies that are stable, widely adopted and have large community support behind them. They include:

  • HTML5 – The latest version of the Hypertext Markup Language. The base code for all web pages.
  • CSS3 – A language and set of rules for styling assets and web content on a website.
  • Bootstrap 4 – A powerful front-end framework developed by Twitter that allows developers to include web components in their applications easily.
  • Material UI – Another powerful front-end framework for React that mimics Google’s Material Design look.
  • jQuery / JavaScript – A client-side processing language for controlling front-end functions and managing data between the front and back-end of websites and applications.

Back-End Technologies remain on a server and are responsible for things like user authentication, some website functionality, data searches and data storage. Technologies that we use are stable, widely adopted and have large community support behind them. They include:

  • Laravel PHP Framework – A popular MVC (model-view-controller) PHP framework used in the development of websites and APIs for mobile development.
  • MySQL – A open source relational database management platform (Structured Query Language). 
  • NGINX – A fast and stable web server / load balancer for websites and APIs.
  • Ubuntu Server – A popular server architecture great for running websites, databases and APIs

Open Source Technologies are community written software projects that are available for free on the internet and can be modified to better fit a company’s needs. Should you need, we can adjust any open source system to meet the requirements of your business.

  • Wordpress – Content management system used to build websites and web applications.
  • WooCommerce – Comprehensive ECommerce plugin for Wordpress.
  • Magento – Standalone eCommerce platform written in PHP.
  • SuiteCRM – Customer relationship manager with built in email marketing capabilities.
  • OpenProject – Team based project management software. 

If you have any questions about the technology we use or if we can support your project contact us.