This plugin generate dynamically PDF files from DB data.
Requirements: wp cli
Steps:
- Add Text Domain and Domain Path as comment for your plugin.
- Create the template file .pot, go into folder or you plugin plugins/myplugin and then: wp i18n make-pot .
- Copy the file from genpdf-woocommerce.pot to genpdf-woocommerce-{lang}.po
- We need to create the file .mo: msgfmt -o file-it_IT.mo file- it_IT.po
- Add load_plugin_textdomain() on plugins_loaded
To protect the access of the customer's signature, I create a folder wp-content/signatures where all signatures will be saved.
- In the table _templates there is the list of templates. To change the PDF template, it is important to create new row in DB and update the id of "_genpdf_id_current_template_pdf" option. Never modify the current HTML of the DB table.
- Some dynamic fields of PDF are from customer data, and some from the product; therefore, by ACF in the admin panel, I created new fields of the product. For the same reason, after the order creation, the plugin saves product metadata into the wc_orders_meta linked to the order_id. In this way, we can guarantee the correct data in case the product is updated in the future.
- In the order list, there are buttons to download a PDF or send an email to the customer with attachments
- After each order with successful payments, the customer will receive an email with all attachments.
- To generate the PDF, I use Dompdf, unfortunately, I commit the vendor folder beacuse I don't have control over the website hosting. Usually the folder vendor is never committed, only the composer.json and composer.lock.