WooCommerce Print Invoice & Delivery Note
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hook Reference
  • Docs Home

Packages

  • None
  • WooCommerce-Delivery-Notes
    • Admin
      • Edit-Order
    • Includes
    • Settings
    • Theme

Classes

  • WCDN_Welcome
  • WooCommerce_Delivery_Notes
  • WooCommerce_Delivery_Notes_Print
  • WooCommerce_Delivery_Notes_Settings
  • WooCommerce_Delivery_Notes_Theme
  • WooCommerce_Delivery_Notes_Writepanel

Functions

  • WCDN
  • wcdn_add_refunded_order_totals
  • wcdn_additional_product_fields
  • wcdn_company_info
  • wcdn_company_logo
  • wcdn_company_name
  • wcdn_content
  • wcdn_customer_notes
  • wcdn_document_title
  • wcdn_get_company_logo_id
  • wcdn_get_customer_notes
  • wcdn_get_formatted_item_price
  • wcdn_get_imprint
  • wcdn_get_order
  • wcdn_get_order_info
  • wcdn_get_order_invoice_date
  • wcdn_get_order_invoice_number
  • wcdn_get_orders
  • wcdn_get_personal_notes
  • wcdn_get_policies_conditions
  • wcdn_get_print_link
  • wcdn_get_template_content
  • wcdn_get_template_title
  • wcdn_get_template_type
  • wcdn_has_customer_notes
  • wcdn_has_refund
  • wcdn_has_shipping_address
  • wcdn_imprint
  • wcdn_navigation
  • wcdn_navigation_style
  • wcdn_personal_notes
  • wcdn_policies_conditions
  • wcdn_remove_payment_method_from_totals
  • wcdn_remove_semicolon_from_totals
  • wcdn_template_stylesheet
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 
<?php
/**
 * Print invoices & delivery notes for WooCommerce orders.
 *
 * Plugin Name: WooCommerce Print Invoice & Delivery Note
 * Plugin URI: https://www.tychesoftwares.com/
 * Description: Print Invoices & Delivery Notes for WooCommerce Orders. 
 * Version: 4.4.1
 * Author: Tyche Softwares
 * Author URI: https://www.tychesoftwares.com/
 * License: GPLv3 or later
 * License URI: http://www.opensource.org/licenses/gpl-license.php
 * Text Domain: woocommerce-delivery-notes
 * Domain Path: /languages
 * Requires PHP: 5.6
 * WC requires at least: 3.0.0
 * WC tested up to: 3.2.0
 *
 * Copyright 2015 Tyche Softwares
 *      
 *     This file is part of WooCommerce Print Invoices & Delivery Notes,
 *     a plugin for WordPress.
 *
 *     WooCommerce Print Invoice & Delivery Note is free software:
 *     You can redistribute it and/or modify it under the terms of the
 *     GNU General Public License as published by the Free Software
 *     Foundation, either version 2 of the License, or (at your option)
 *     any later version.
 *
 *     WooCommerce Print Invoice & Delivery Note is distributed in the hope that
 *     it will be useful, but WITHOUT ANY WARRANTY; without even the
 *     implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 *     PURPOSE. See the GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with WordPress. If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * Exit if accessed directly
 */
if ( !defined( 'ABSPATH' ) ) {
    exit; 
}

/**
 * Base class
 */
if ( !class_exists( 'WooCommerce_Delivery_Notes' ) ) {
    /**
     * WooCommerce Delivery Notes
     * 
     * @author Tyche Softwares
     * @package WooCommerce-Delivery-Notes
     */
    final class WooCommerce_Delivery_Notes {
 
        /**
         * The single instance of the class
         */
        protected static $_instance = null;
    
        /**
         * Default properties
         */
        public static $plugin_version = '4.4';
        public static $plugin_url;
        public static $plugin_path;
        public static $plugin_basefile;
        public static $plugin_basefile_path;
        public static $plugin_text_domain;
        
        /**
         * Sub class instances
         */
        public $writepanel;
        public $settings;
        public $print;
        public $theme;

        /**
         * Main Instance
         */
        public static function instance() {
            if( is_null( self::$_instance ) ) {
                self::$_instance = new self();
            }
            return self::$_instance;
        }
    
        /**
         * Cloning is forbidden
         */
        public function __clone() {
            _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woocommerce-delivery-notes' ), '4.1' );
        }
    
        /**
         * Unserializing instances of this class is forbidden
         */
        public function __wakeup() {
            _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woocommerce-delivery-notes' ), '4.1' );
        }

        /**
         * Constructor
         */
        public function __construct() {
            $this->define_constants();
            $this->init_hooks();
            
            // Send out the load action
            do_action( 'wcdn_load');
        }

        /**
         * Hook into actions and filters
         */
        public function init_hooks() {
            add_action( 'init', array( $this, 'localise' ) );
            add_action( 'woocommerce_init', array( $this, 'load' ) );
        }

        /**
         * Define WC Constants
         */
        private function define_constants() {
            self::$plugin_basefile_path = __FILE__;
            self::$plugin_basefile = plugin_basename( self::$plugin_basefile_path );
            self::$plugin_url = plugin_dir_url( self::$plugin_basefile );
            self::$plugin_path = trailingslashit( dirname( self::$plugin_basefile_path ) ); 
            self::$plugin_text_domain = trim( dirname( self::$plugin_basefile ) );      
        }
        
        /**
         * Define constant if not already set
         */
        private function define( $name, $value ) {

            if( !defined( $name ) ) {
                define( $name, $value );
            }
        }
        
        /**
         * Include the main plugin classes and functions
         */
        public function include_classes() {
            include_once( 'includes/class-wcdn-print.php' );
            include_once( 'includes/class-wcdn-settings.php' );
            include_once( 'includes/class-wcdn-writepanel.php' );
            include_once( 'includes/class-wcdn-theme.php' );
            if ( is_admin() ) {
                include_once( 'includes/wcdn-welcome.php' );
            }
        }

        /**
         * Function used to init Template Functions.
         * This makes them pluggable by plugins and themes.
         */
        public function include_template_functions() {
            include_once( 'includes/wcdn-template-functions.php' );
            include_once( 'includes/wcdn-template-hooks.php' );
        }
        
        /**
         * Load the localisation 
         */
        public function localise() {                            
            // Load language files from the wp-content/languages/plugins folder
            $mo_file = WP_LANG_DIR . '/plugins/' . self::$plugin_text_domain . '-' . get_locale() . '.mo';
            if( is_readable( $mo_file ) ) {
                load_textdomain( self::$plugin_text_domain, $mo_file );
            }

            // Otherwise load them from the plugin folder
            load_plugin_textdomain( self::$plugin_text_domain, false, dirname( self::$plugin_basefile ) . '/languages/' );
        }
        
        /**
         * Load the main plugin classes and functions
         */
        public function load() {
            // WooCommerce activation required
            if ( $this->is_woocommerce_activated() ) {  
                // Include the classes  
                $this->include_classes();
                            
                // Create the instances
                $this->print = new WooCommerce_Delivery_Notes_Print();
                $this->settings = new WooCommerce_Delivery_Notes_Settings();
                $this->writepanel = new WooCommerce_Delivery_Notes_Writepanel();
                $this->theme = new WooCommerce_Delivery_Notes_Theme();

                // Load the hooks for the template after the objetcs.
                // Like this the template has full access to all objects.
                add_filter( 'plugin_action_links_' . self::$plugin_basefile, array( $this, 'add_settings_link') );
                add_action( 'admin_init', array( $this, 'update' ) );
                add_action( 'init', array( $this, 'include_template_functions' ) );
                
                // Send out the init action
                do_action( 'wcdn_init');
            }
        }
                
        /**
         * Install or update the default settings
         */
        public function update() {
            $option_version = get_option( 'wcdn_version', '1' );

            // Update the settings
            if( version_compare( $option_version, self::$plugin_version, '<' ) ) {
                // Legacy updates
                if( version_compare( $option_version, '4.2.0', '<' ) ) {
                    // Group invoice numbering
                    $invoice_start = intval( get_option( 'wcdn_invoice_number_start', 1 ) );
                    $invoice_counter = intval( get_option( 'wcdn_invoice_number_counter', 0 ) );
                    update_option( 'wcdn_invoice_number_count', $invoice_start + $invoice_counter );    
                    
                    // Translate checkbox values
                    foreach( $this->settings->get_settings() as $value ) {
                        if( isset( $value['id'] ) && isset( $value['type'] ) && $value['type'] == 'checkbox' ) {
                            $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
                            $option = get_option( $value['id'] );
                            if( (bool)$option ) {
                                update_option( $value['id'], 'yes' );   
                            } else {
                                update_option( $value['id'], 'no' );    
                            }
                        }
                    }               
                }
                
                // Set all options that have default values
                foreach( $this->settings->get_settings() as $value ) {
                    if( isset( $value['default'] ) && isset( $value['id'] ) ) {
                        $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
                        add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
                    }
                }
                
                // Flush the transients in case the endpoint changed
                set_transient( 'wcdn_flush_rewrite_rules', true );

                // Update the settings to the latest version
                update_option( 'wcdn_version', self::$plugin_version );
            }
        }
        
        /**
         * Add settings link to plugin page
         */
        public function add_settings_link( $links ) {
            $url = esc_url( admin_url( add_query_arg( array( 'page' => 'wc-settings', 'tab' => $this->settings->id ), 'admin.php' ) ) );
            $settings = sprintf( '<a href="%s" title="%s">%s</a>' , $url, __( 'Go to the settings page', 'woocommerce-delivery-notes' ) , __( 'Settings', 'woocommerce-delivery-notes' ) );
            array_unshift( $links, $settings );
            return $links;  
        }
                
        /**
         * Check if woocommerce is activated
         */
        public function is_woocommerce_activated() {
            $blog_plugins = get_option( 'active_plugins', array() );
            $site_plugins = get_site_option( 'active_sitewide_plugins', array() );
            $woocommerce_basename = plugin_basename( WC_PLUGIN_FILE );
                    
            if( ( in_array( $woocommerce_basename, $blog_plugins ) || isset( $site_plugins[$woocommerce_basename] ) ) && version_compare( WC_VERSION, '2.2', '>=' ) ) {
                return true;
            } else {
                return false;
            }
        }
        
    }
}

/**
 * Returns the main instance of the plugin to prevent the need to use globals
 */
function WCDN() {
    return WooCommerce_Delivery_Notes::instance();
}

/**
 * Global for backwards compatibility
 */
$GLOBALS['wcdn'] = WCDN();

?>
WooCommerce Print Invoice & Delivery Note API documentation generated by ApiGen