WooCommerce_PDF_Invoices

The WooCommerce PDF Invoices & Packing Slips WooCommerce PDF Invoices class.

Defined (1)

The class is defined in the following location(s).

/woocommerce-pdf-invoices-packingslips.php  
  1. class WooCommerce_PDF_Invoices { 
  2.  
  3. public static $plugin_prefix; 
  4. public static $plugin_url; 
  5. public static $plugin_path; 
  6. public static $plugin_basename; 
  7. public static $version; 
  8.  
  9. public $writepanels; 
  10. public $settings; 
  11. public $export; 
  12.  
  13. protected static $_instance = null; 
  14.  
  15. /** 
  16. * Main Plugin Instance 
  17. * Ensures only one instance of plugin is loaded or can be loaded. 
  18. */ 
  19. public static function instance() { 
  20. if ( is_null( self::$_instance ) ) { 
  21. self::$_instance = new self(); 
  22. return self::$_instance; 
  23.  
  24. /** 
  25. * Constructor 
  26. */ 
  27. public function __construct() { 
  28. self::$plugin_prefix = 'wpo_wcpdf_'; 
  29. self::$plugin_basename = plugin_basename(__FILE__); 
  30. self::$plugin_url = plugin_dir_url(self::$plugin_basename); 
  31. self::$plugin_path = trailingslashit(dirname(__FILE__)); 
  32. self::$version = '1.6.5'; 
  33.  
  34. // load the localisation & classes 
  35. add_action( 'plugins_loaded', array( $this, 'translations' ) ); // or use init? 
  36. add_action( 'init', array( $this, 'load_classes' ) ); 
  37.  
  38. // run lifecycle methods 
  39. if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { 
  40. // check if upgrading from versionless (1.4.14 and older) 
  41. if ( get_option('wpo_wcpdf_general_settings') && get_option('wpo_wcpdf_version') === false ) { 
  42. // tag 'versionless', so that we can apply necessary upgrade settings 
  43. add_option( 'wpo_wcpdf_version', 'versionless' ); 
  44.  
  45. add_action( 'wp_loaded', array( $this, 'do_install' ) ); 
  46.  
  47. /** 
  48. * Load the translation / textdomain files 
  49. *  
  50. * Note: the first-loaded translation file overrides any following ones if the same translation is present 
  51. */ 
  52. public function translations() { 
  53. $locale = apply_filters( 'plugin_locale', get_locale(), 'wpo_wcpdf' ); 
  54. $dir = trailingslashit( WP_LANG_DIR ); 
  55.  
  56. /** 
  57. * Frontend/global Locale. Looks in: 
  58. * - WP_LANG_DIR/woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-LOCALE.mo 
  59. * - WP_LANG_DIR/plugins/wpo_wcpdf-LOCALE.mo 
  60. * - woocommerce-pdf-invoices-packing-slips/languages/wpo_wcpdf-LOCALE.mo (which if not found falls back to:) 
  61. * - WP_LANG_DIR/plugins/wpo_wcpdf-LOCALE.mo 
  62. */ 
  63. load_textdomain( 'wpo_wcpdf', $dir . 'woocommerce-pdf-invoices-packing-slips/wpo_wcpdf-' . $locale . '.mo' ); 
  64. load_textdomain( 'wpo_wcpdf', $dir . 'plugins/wpo_wcpdf-' . $locale . '.mo' ); 
  65. load_plugin_textdomain( 'wpo_wcpdf', false, dirname( self::$plugin_basename ) . '/languages' ); 
  66.  
  67. /** 
  68. * Load the main plugin classes and functions 
  69. */ 
  70. public function includes() { 
  71. include_once( 'includes/class-wcpdf-settings.php' ); 
  72. include_once( 'includes/class-wcpdf-writepanels.php' ); 
  73. include_once( 'includes/class-wcpdf-export.php' ); 
  74. include_once( 'includes/class-wcpdf-functions.php' ); 
  75.  
  76. // compatibility classes 
  77. include_once( 'includes/compatibility/abstract-wc-data-compatibility.php' ); 
  78. include_once( 'includes/compatibility/class-wc-date-compatibility.php' ); 
  79. include_once( 'includes/compatibility/class-wc-core-compatibility.php' ); 
  80. include_once( 'includes/compatibility/class-wc-order-compatibility.php' ); 
  81. include_once( 'includes/compatibility/class-wc-product-compatibility.php' ); 
  82.  
  83.  
  84. /** 
  85. * Instantiate classes when woocommerce is activated 
  86. */ 
  87. public function load_classes() { 
  88. if ( $this->is_woocommerce_activated() === false ) { 
  89. add_action( 'admin_notices', array ( $this, 'need_woocommerce' ) ); 
  90. return; 
  91.  
  92. if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { 
  93. add_action( 'admin_notices', array ( $this, 'required_php_version' ) ); 
  94. return; 
  95.  
  96. // all systems ready - GO! 
  97. $this->includes(); 
  98. $this->settings = new WooCommerce_PDF_Invoices_Settings(); 
  99. $this->writepanels = new WooCommerce_PDF_Invoices_Writepanels(); 
  100. $this->export = new WooCommerce_PDF_Invoices_Export(); 
  101. $this->functions = new WooCommerce_PDF_Invoices_Functions(); 
  102.  
  103. /** 
  104. * Check if woocommerce is activated 
  105. */ 
  106. public function is_woocommerce_activated() { 
  107. $blog_plugins = get_option( 'active_plugins', array() ); 
  108. $site_plugins = is_multisite() ? (array) maybe_unserialize( get_site_option('active_sitewide_plugins' ) ) : array(); 
  109.  
  110. if ( in_array( 'woocommerce/woocommerce.php', $blog_plugins ) || isset( $site_plugins['woocommerce/woocommerce.php'] ) ) { 
  111. return true; 
  112. } else { 
  113. return false; 
  114.  
  115. /** 
  116. * WooCommerce not active notice. 
  117. * @return string Fallack notice. 
  118. */ 
  119.  
  120. public function need_woocommerce() { 
  121. $error = sprintf( __( 'WooCommerce PDF Invoices & Packing Slips requires %sWooCommerce%s to be installed & activated!' , 'wpo_wcpdf' ), '<a href="http://wordpress.org/extend/plugins/woocommerce/">', '</a>' ); 
  122.  
  123. $message = '<div class="error"><p>' . $error . '</p></div>'; 
  124.  
  125. echo $message; 
  126.  
  127. /** 
  128. * PHP version requirement notice 
  129. */ 
  130.  
  131. public function required_php_version() { 
  132. $error = __( 'WooCommerce PDF Invoices & Packing Slips requires PHP 5.3 or higher (5.6 or higher recommended).', 'wpo_wcpdf' ); 
  133. $how_to_update = __( 'How to update your PHP version', 'wpo_wcpdf' ); 
  134. $message = sprintf('<div class="error"><p>%s</p><p><a href="%s">%s</a></p></div>', $error, 'http://docs.wpovernight.com/general/how-to-update-your-php-version/', $how_to_update); 
  135.  
  136. echo $message; 
  137.  
  138. /** Lifecycle methods ******************************************************* 
  139. * Because register_activation_hook only runs when the plugin is manually 
  140. * activated by the user, we're checking the current version against the 
  141. * version stored in the database 
  142. ****************************************************************************/ 
  143.  
  144. /** 
  145. * Handles version checking 
  146. */ 
  147. public function do_install() { 
  148. // only install when woocommerce is active and PHP version 5.3 or higher 
  149. if ( !$this->is_woocommerce_activated() || version_compare( PHP_VERSION, '5.3', '<' ) ) { 
  150. return; 
  151.  
  152. $version_setting = 'wpo_wcpdf_version'; 
  153. $installed_version = get_option( $version_setting ); 
  154.  
  155. // installed version lower than plugin version? 
  156. if ( version_compare( $installed_version, self::$version, '<' ) ) { 
  157.  
  158. if ( ! $installed_version ) { 
  159. $this->install(); 
  160. } else { 
  161. $this->upgrade( $installed_version ); 
  162.  
  163. // new version number 
  164. update_option( $version_setting, self::$version ); 
  165.  
  166.  
  167. /** 
  168. * Plugin install method. Perform any installation tasks here 
  169. */ 
  170. protected function install() { 
  171. // Create temp folders 
  172. $tmp_base = $this->export->get_tmp_base(); 
  173.  
  174. // check if tmp folder exists => if not, initialize  
  175. if ( !@is_dir( $tmp_base ) ) { 
  176. $this->export->init_tmp( $tmp_base ); 
  177.  
  178.  
  179.  
  180. /** 
  181. * Plugin upgrade method. Perform any required upgrades here 
  182. * @param string $installed_version the currently installed version 
  183. */ 
  184. protected function upgrade( $installed_version ) { 
  185. if ( $installed_version == 'versionless') { // versionless = 1.4.14 and older 
  186. // We're upgrading from an old version, so we're enabling the option to use the plugin tmp folder. 
  187. // This is not per se the 'best' solution, but the good thing is that nothing is changed 
  188. // and nothing will be broken (that wasn't broken before) 
  189. $default = array( 'old_tmp' => 1 ); 
  190. update_option( 'wpo_wcpdf_debug_settings', $default ); 
  191.  
  192. // sync fonts on every upgrade! 
  193. $debug_settings = get_option( 'wpo_wcpdf_debug_settings' ); // get temp setting 
  194.  
  195. // do not copy if old_tmp function active! (double check for slow databases) 
  196. if ( !( isset($debug_settings['old_tmp']) || $installed_version == 'versionless' ) ) { 
  197. $tmp_base = $this->export->get_tmp_base(); 
  198.  
  199. // check if tmp folder exists => if not, initialize  
  200. if ( !@is_dir( $tmp_base ) ) { 
  201. $this->export->init_tmp( $tmp_base ); 
  202.  
  203. $font_path = $tmp_base . 'fonts/'; 
  204. $this->export->copy_fonts( $font_path ); 
  205.  
  206. // 1.5.28 update: copy next invoice number to separate setting 
  207. if ( $installed_version == 'versionless' || version_compare( $installed_version, '1.5.28', '<' ) ) { 
  208. $template_settings = get_option( 'wpo_wcpdf_template_settings' ); 
  209. $next_invoice_number = isset($template_settings['next_invoice_number'])?$template_settings['next_invoice_number']:''; 
  210. update_option( 'wpo_wcpdf_next_invoice_number', $next_invoice_number ); 
  211. }  
  212.  
  213. /***********************************************************************/ 
  214. /********************** GENERAL TEMPLATE FUNCTIONS *********************/ 
  215. /***********************************************************************/ 
  216.  
  217. /** 
  218. * Get template name from slug 
  219. */ 
  220. public function get_template_name ( $template_type ) { 
  221. return $this->functions->get_template_name( $template_type ); 
  222.  
  223. /** 
  224. * Output template styles 
  225. */ 
  226. public function template_styles() { 
  227. $this->functions->template_styles(); 
  228. }  
  229.  
  230. /** 
  231. * Return logo id 
  232. */ 
  233. public function get_header_logo_id() { 
  234. return $this->functions->get_header_logo_id(); 
  235.  
  236. /** 
  237. * Show logo html 
  238. */ 
  239. public function header_logo() { 
  240. $this->functions->header_logo(); 
  241.  
  242. /** 
  243. * Return/Show custom company name or default to blog name 
  244. */ 
  245. public function get_shop_name() { 
  246. return $this->functions->get_shop_name(); 
  247. public function shop_name() { 
  248. $this->functions->shop_name(); 
  249.  
  250. /** 
  251. * Return/Show shop/company address if provided 
  252. */ 
  253. public function get_shop_address() { 
  254. return $this->functions->get_shop_address(); 
  255. public function shop_address() { 
  256. $this->functions->shop_address(); 
  257.  
  258. /** 
  259. * Check if billing address and shipping address are equal 
  260. */ 
  261. public function ships_to_different_address() { 
  262. return $this->functions->ships_to_different_address(); 
  263.  
  264. /** 
  265. * Return/Show billing address 
  266. */ 
  267. public function get_billing_address() { 
  268. return $this->functions->get_billing_address(); 
  269. public function billing_address() { 
  270. $this->functions->billing_address(); 
  271.  
  272. /** 
  273. * Return/Show billing email 
  274. */ 
  275. public function get_billing_email() { 
  276. return $this->functions->get_billing_email(); 
  277. public function billing_email() { 
  278. $this->functions->billing_email(); 
  279.  
  280. /** 
  281. * Return/Show billing phone 
  282. */ 
  283. public function get_billing_phone() { 
  284. return $this->functions->get_billing_phone(); 
  285. public function billing_phone() { 
  286. $this->functions->billing_phone(); 
  287.  
  288. /** 
  289. * Return/Show shipping address 
  290. */ 
  291. public function get_shipping_address() { 
  292. return $this->functions->get_shipping_address(); 
  293. public function shipping_address() { 
  294. $this->functions->shipping_address(); 
  295.  
  296. /** 
  297. * Return/Show a custom field 
  298. */  
  299. public function get_custom_field( $field_name ) { 
  300. return $this->functions->get_custom_field( $field_name ); 
  301. public function custom_field( $field_name, $field_label = '', $display_empty = false ) { 
  302. $this->functions->custom_field( $field_name, $field_label, $display_empty ); 
  303.  
  304. /** 
  305. * Return/Show order notes 
  306. */  
  307. public function get_order_notes( $filter = 'customer' ) { 
  308. return $this->functions->get_order_notes( $filter ); 
  309. public function order_notes( $filter = 'customer' ) { 
  310. $this->functions->order_notes( $filter ); 
  311.  
  312. /** 
  313. * Return/Show the current date 
  314. */ 
  315. public function get_current_date() { 
  316. return $this->functions->get_current_date(); 
  317. public function current_date() { 
  318. $this->functions->current_date(); 
  319.  
  320. /** 
  321. * Return/Show payment method  
  322. */ 
  323. public function get_payment_method() { 
  324. return $this->functions->get_payment_method(); 
  325. public function payment_method() { 
  326. $this->functions->payment_method(); 
  327.  
  328. /** 
  329. * Return/Show shipping method  
  330. */ 
  331. public function get_shipping_method() { 
  332. return $this->functions->get_shipping_method(); 
  333. public function shipping_method() { 
  334. $this->functions->shipping_method(); 
  335.  
  336. /** 
  337. * Return/Show order number 
  338. */ 
  339. public function get_order_number() { 
  340. return $this->functions->get_order_number(); 
  341. public function order_number() { 
  342. $this->functions->order_number(); 
  343.  
  344. /** 
  345. * Return/Show invoice number  
  346. */ 
  347. public function get_invoice_number() { 
  348. return $this->functions->get_invoice_number(); 
  349. public function invoice_number() { 
  350. $this->functions->invoice_number(); 
  351.  
  352. /** 
  353. * Return/Show the order date 
  354. */ 
  355. public function get_order_date() { 
  356. return $this->functions->get_order_date(); 
  357. public function order_date() { 
  358. $this->functions->order_date(); 
  359.  
  360. /** 
  361. * Return/Show the invoice date 
  362. */ 
  363. public function get_invoice_date() { 
  364. return $this->functions->get_invoice_date(); 
  365. public function invoice_date() { 
  366. $this->functions->invoice_date(); 
  367.  
  368. /** 
  369. * Return the order items 
  370. */ 
  371. public function get_order_items() { 
  372. return $this->functions->get_order_items(); 
  373.  
  374. /** 
  375. * Return/show product attribute 
  376. */ 
  377. public function get_product_attribute( $attribute_name, $product ) { 
  378. return $this->functions->get_product_attribute( $attribute_name, $product ); 
  379. public function product_attribute( $attribute_name, $product ) { 
  380. $this->functions->product_attribute( $attribute_name, $product ); 
  381.  
  382.  
  383. /** 
  384. * Return the order totals listing 
  385. */ 
  386. public function get_woocommerce_totals() { 
  387. return $this->functions->get_woocommerce_totals(); 
  388.  
  389. /** 
  390. * Return/show the order subtotal 
  391. */ 
  392. public function get_order_subtotal( $tax = 'excl', $discount = 'incl' ) { // set $tax to 'incl' to include tax, same for $discount 
  393. return $this->functions->get_order_subtotal( $tax, $discount ); 
  394. public function order_subtotal( $tax = 'excl', $discount = 'incl' ) { 
  395. $this->functions->order_subtotal( $tax, $discount ); 
  396.  
  397. /** 
  398. * Return/show the order shipping costs 
  399. */ 
  400. public function get_order_shipping( $tax = 'excl' ) { // set $tax to 'incl' to include tax 
  401. return $this->functions->get_order_shipping( $tax ); 
  402. public function order_shipping( $tax = 'excl' ) { 
  403. $this->functions->order_shipping( $tax ); 
  404.  
  405. /** 
  406. * Return/show the total discount 
  407. */ 
  408. public function get_order_discount( $type = 'total', $tax = 'incl' ) { 
  409. return $this->functions->get_order_discount( $type, $tax ); 
  410. public function order_discount( $type = 'total', $tax = 'incl' ) { 
  411. $this->functions->order_discount( $type, $tax ); 
  412.  
  413. /** 
  414. * Return the order fees 
  415. */ 
  416. public function get_order_fees( $tax = 'excl' ) { 
  417. return $this->functions->get_order_fees( $tax ); 
  418.  
  419. /** 
  420. * Return the order taxes 
  421. */ 
  422. public function get_order_taxes() { 
  423. return $this->functions->get_order_taxes(); 
  424.  
  425. /** 
  426. * Return/show the order grand total 
  427. */ 
  428. public function get_order_grand_total( $tax = 'incl' ) { 
  429. return $this->functions->get_order_grand_total( $tax ); 
  430. public function order_grand_total( $tax = 'incl' ) { 
  431. $this->functions->order_grand_total( $tax ); 
  432.  
  433.  
  434. /** 
  435. * Return/Show shipping notes 
  436. */ 
  437. public function get_shipping_notes() { 
  438. return $this->functions->get_shipping_notes(); 
  439. public function shipping_notes() { 
  440. $this->functions->shipping_notes(); 
  441.  
  442.  
  443. /** 
  444. * Return/Show shop/company footer imprint, copyright etc. 
  445. */ 
  446. public function get_footer() { 
  447. return $this->functions->get_footer(); 
  448. public function footer() { 
  449. $this->functions->footer(); 
  450.  
  451. /** 
  452. * Return/Show Extra field 1 
  453. */ 
  454. public function get_extra_1() { 
  455. return $this->functions->get_extra_1(); 
  456. public function extra_1() { 
  457. $this->functions->extra_1(); 
  458.  
  459. /** 
  460. * Return/Show Extra field 2 
  461. */ 
  462. public function get_extra_2() { 
  463. return $this->functions->get_extra_2(); 
  464. public function extra_2() { 
  465. $this->functions->extra_2(); 
  466.  
  467. /** 
  468. * Return/Show Extra field 3 
  469. */ 
  470. public function get_extra_3() { 
  471. return $this->functions->get_extra_3(); 
  472. public function extra_3() { 
  473. $this->functions->extra_3();