We’re going to create a PDF for WooCommerce products using DK PDF. We’ll create a PDF that shows the following WooCommerce information: Title, Featured image, Description, Price and a Link to product.
- WordPress installation with WooCommerce and DK PDF.
- Code editor, I’m using Sublime Text in this tutorial.
- 1. Copy plugin templates in Theme (or Child theme).
- 2. Get WooCommerce product information.
- 3. Create PDF HTML layout.
1. Copy plugin templates in Theme
DK PDF implements a template system that allows overriding plugin templates in an upgrade safe way, I’m using this system in all my latest plugins, DPortfolio and Docu are using the same template system.
2. Get WooCommerce product information
Check product post type in Settings / PDF Button / Post types to apply.
The first thing to do is get the information from WordPress database, open dkpdf-index.php template in your favourite code editor and replace body content.
3. Create PDF HTML layout
This is the Layout we’ll try to replicate in the PDF.
For the sake of simplicity, We’re not going to cover adding custom fonts to the PDF, this will come in a next tutorial 🙂
Final code for body:
Replace default CSS style:
We’re done 🙂 I hope you enjoyed this tutorial, feel free to visit the demo and leave a comment here if you have any doubt.