WooCommerce_Delivery_Notes

The WooCommerce Print Invoice & Delivery Note WooCommerce Delivery Notes class.

Defined (1)

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

/woocommerce-delivery-notes.php  
  1. final class WooCommerce_Delivery_Notes { 
  2.  
  3. public static $plugin_prefix; 
  4. public static $plugin_url; 
  5. public static $plugin_path; 
  6. public static $plugin_basefile; 
  7. public static $plugin_basefile_path; 
  8.  
  9. public $writepanel; 
  10. public $settings; 
  11. public $print; 
  12. public $theme; 
  13.  
  14. /** 
  15. * Constructor 
  16. */ 
  17. public function __construct() { 
  18. // Define the constants 
  19. self::$plugin_prefix = 'wcdn_'; 
  20. self::$plugin_basefile_path = __FILE__; 
  21. self::$plugin_basefile = plugin_basename( self::$plugin_basefile_path ); 
  22. self::$plugin_url = plugin_dir_url( self::$plugin_basefile ); 
  23. self::$plugin_path = trailingslashit( dirname( self::$plugin_basefile_path ) );  
  24.  
  25. // Set hooks and wait for WooCommerce to load 
  26. register_activation_hook( self::$plugin_basefile_path, array( $this, 'install' ) ); 
  27. add_action( 'plugins_loaded', array( $this, 'localise' ) ); 
  28. add_action( 'woocommerce_init', array( $this, 'load' ) ); 
  29.  
  30. /** 
  31. * Include the main plugin classes and functions 
  32. */ 
  33. public function include_classes() { 
  34. include_once( 'includes/class-wcdn-print.php' ); 
  35. include_once( 'includes/class-wcdn-settings.php' ); 
  36. include_once( 'includes/class-wcdn-writepanel.php' ); 
  37. include_once( 'includes/class-wcdn-theme.php' ); 
  38.  
  39. /** 
  40. * Function used to init Template Functions. 
  41. * This makes them pluggable by plugins and themes. 
  42. */ 
  43. public function include_template_functions() { 
  44. include_once( 'includes/wcdn-template-functions.php' ); 
  45. include_once( 'includes/wcdn-template-hooks.php' ); 
  46.  
  47. /** 
  48. * Install the defaults on activation 
  49. */ 
  50. public function install() { 
  51. // Define default settings 
  52. $option = get_option( self::$plugin_prefix . 'print_order_page_endpoint' ); 
  53. if( !$option ) { 
  54. update_option( self::$plugin_prefix . 'print_order_page_endpoint', 'print-order' ); 
  55.  
  56. // Flush the rewrite rules when a fresh install 
  57. set_transient( self::$plugin_prefix . 'flush_rewrite_rules', true ); 
  58.  
  59. /** 
  60. * Load the localisation  
  61. */ 
  62. public function localise() {  
  63. load_plugin_textdomain( 'woocommerce-delivery-notes', false, dirname( self::$plugin_basefile ) . '/languages/' ); 
  64.  
  65. /** 
  66. * Include the main plugin classes and functions 
  67. */ 
  68. public function load() { 
  69. // WooCommerce activation required 
  70. if ( $this->is_woocommerce_activated() ) {  
  71. // Include the classes  
  72. $this->include_classes(); 
  73.  
  74. // Create the instances 
  75. $this->print = new WooCommerce_Delivery_Notes_Print(); 
  76. $this->settings = new WooCommerce_Delivery_Notes_Settings(); 
  77. $this->writepanel = new WooCommerce_Delivery_Notes_Writepanel(); 
  78. $this->theme = new WooCommerce_Delivery_Notes_Theme(); 
  79.  
  80. // Load the hooks for the template after the objetcs. 
  81. // Like this the template has full access to all objects. 
  82. add_action( 'admin_init', array( $this, 'load_admin_hooks' ) ); 
  83. add_action( 'init', array( $this, 'include_template_functions' ) ); 
  84.  
  85. /** 
  86. * Load the admin hooks 
  87. */ 
  88. public function load_admin_hooks() { 
  89. add_filter( 'plugin_action_links_' . self::$plugin_basefile, array( $this, 'add_settings_link') ); 
  90.  
  91. /** 
  92. * Add settings link to plugin page 
  93. */ 
  94. public function add_settings_link( $links ) { 
  95. $settings = sprintf( '<a href="%s" title="%s">%s</a>' , admin_url( 'admin.php?page=woocommerce&tab=' . $this->settings->tab_name ) , __( 'Go to the settings page', 'woocommerce-delivery-notes' ) , __( 'Settings', 'woocommerce-delivery-notes' ) ); 
  96. array_unshift( $links, $settings ); 
  97. return $links;  
  98.  
  99. /** 
  100. * Check if woocommerce is activated 
  101. */ 
  102. public function is_woocommerce_activated() { 
  103. $blog_plugins = get_option( 'active_plugins', array() ); 
  104. $site_plugins = get_site_option( 'active_sitewide_plugins', array() ); 
  105. $woocommerce_basename = plugin_basename( WC_PLUGIN_FILE ); 
  106.  
  107. if( ( in_array( $woocommerce_basename, $blog_plugins ) || isset( $site_plugins[$woocommerce_basename] ) ) && version_compare( WC_VERSION, '2.1', '>=' )) { 
  108. return true; 
  109. } else { 
  110. return false; 
  111.