WooCommerce_Delivery_Notes_Settings

The WooCommerce Print Invoices & Delivery Notes WooCommerce Delivery Notes Settings class.

Defined (1)

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

/classes/class-wcdn-settings.php  
  1. class WooCommerce_Delivery_Notes_Settings { 
  2.  
  3. public $tab_name; 
  4. public $hidden_submit; 
  5.  
  6. /** 
  7. * Constructor 
  8. */ 
  9. public function __construct() {  
  10. $this->tab_name = 'woocommerce-delivery-notes'; 
  11. $this->hidden_submit = WooCommerce_Delivery_Notes::$plugin_prefix . 'submit'; 
  12.  
  13. /** 
  14. * Load the class 
  15. */ 
  16. public function load() { 
  17. add_action( 'admin_init', array( $this, 'load_hooks' ) ); 
  18.  
  19. /** 
  20. * Load the admin hooks 
  21. */ 
  22. public function load_hooks() {  
  23. add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_tab' ) ); 
  24. add_action( 'woocommerce_settings_tabs_' . $this->tab_name, array( $this, 'create_settings_page' ) ); 
  25. add_action( 'woocommerce_update_options_' . $this->tab_name, array( $this, 'save_settings_page' ) ); 
  26. add_action( 'current_screen', array( $this, 'load_screen_hooks' ) ); 
  27. add_action( 'wp_ajax_load_thumbnail', array( $this, 'load_thumbnail_ajax' ) ); 
  28.  
  29. /** 
  30. * Add the scripts 
  31. */ 
  32. public function load_screen_hooks() { 
  33. $screen = get_current_screen(); 
  34.  
  35. if( $this->is_settings_page() ) { 
  36. add_action( 'admin_print_styles', array( $this, 'add_styles' ) ); 
  37. add_action( 'admin_print_scripts', array( $this, 'add_scripts' ) ); 
  38. add_action( 'load-' . $screen->id, array( $this, 'add_help_tabs' ) ); 
  39.  
  40. if( $this->is_media_uploader_page() ) { 
  41. add_filter( 'media_upload_tabs', array( $this, 'remove_media_tabs' ) ); 
  42.  
  43. /** 
  44. * Add the styles 
  45. */ 
  46. public function add_styles() { 
  47. wp_enqueue_style( 'thickbox' ); 
  48. wp_enqueue_style( 'woocommerce-delivery-notes', WooCommerce_Delivery_Notes::$plugin_url . 'css/style.css' ); 
  49.  
  50. /** 
  51. * Add the scripts 
  52. */ 
  53. public function add_scripts() { 
  54. ?> 
  55. <script type="text/javascript"> 
  56. var show_print_preview = 'yes'; 
  57. </script> 
  58. <?php  
  59. wp_enqueue_script( 'media-upload' ); 
  60. wp_enqueue_script( 'thickbox' ); 
  61. wp_enqueue_script( 'woocommerce-delivery-notes', WooCommerce_Delivery_Notes::$plugin_url . 'js/script.js', array( 'jquery', 'media-upload', 'thickbox' ) ); 
  62.  
  63. /** 
  64. * Check if we are on settings page 
  65. */ 
  66. public function is_settings_page() { 
  67. if( isset( $_GET['page'] ) && isset( $_GET['tab'] ) && $_GET['tab'] == $this->tab_name ) { 
  68. return true; 
  69. } else { 
  70. return false; 
  71.  
  72. /** 
  73. * Check if we are on media uploader page 
  74. */ 
  75. public function is_media_uploader_page() { 
  76. if( isset( $_GET['post_id'] ) && isset( $_GET['company_logo_image'] ) && $_GET['post_id'] == '0' && $_GET['company_logo_image'] == 'true' ) { 
  77. return true; 
  78. } else { 
  79. return false; 
  80.  
  81. /** 
  82. * Check if sequential order plugin is activated 
  83. */ 
  84. public function is_woocommerce_sequential_order_numbers_activated() { 
  85. if ( in_array( 'woocommerce-sequential-order-numbers/woocommerce-sequential-order-numbers.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 
  86. return true; 
  87. } else { 
  88. return false; 
  89.  
  90. /** 
  91. * Remove the media uploader tabs 
  92. */ 
  93. public function remove_media_tabs( $tabs ) { 
  94. unset( $tabs['type_url'] ); 
  95. return $tabs; 
  96.  
  97. /** 
  98. * Add the help tabs 
  99. */ 
  100. public function add_help_tabs() { 
  101. // Check current admin screen 
  102. $screen = get_current_screen(); 
  103.  
  104. // Remove all existing tabs 
  105. $screen->remove_help_tabs(); 
  106.  
  107. // Create arrays with help tab titles 
  108. $screen->add_help_tab(array( 
  109. 'id' => 'woocommerce-delivery-notes-usage',  
  110. 'title' => __( 'About the Plugin', 'woocommerce-delivery-notes' ),  
  111. 'content' =>  
  112. '<h3>' . __( 'Plugin: WooCommerce Print Invoices & Delivery Notes', 'woocommerce-delivery-notes' ) . '</h3>' . 
  113. '<h4>' . __( 'About the Plugin', 'woocommerce-delivery-notes' ) . '</h4>' . 
  114. '<p>' . __( 'This plugin enables you to add a Invoice or simple Delivery Note page for printing for your orders in WooCommerce shop plugin. You can add your company postal address, further add personal notes, refund or other policies and a footer note/branding. This helps speed up your daily shop and order management. In some countries (e.g. in the European Union) it is also required to advice the customer with proper refund policies so this little plugin might help you a bit with that too.', 'woocommerce-delivery-notes' ) . '</p>' . 
  115. '<p>' . sprintf( __( 'Just look under <a href="%1$s">WooCommerce > Orders</a> and there go to a single order view. On the right side you will see the Order Print meta box. Click one of the buttons and you get the invoice or delivery note printing page. Yes, it is that easy :-).', 'woocommerce-delivery-notes' ), admin_url( 'edit.php?post_type=shop_order' ) ) . '</p>' 
  116. ) ); 
  117.  
  118. // Create help sidebar 
  119. $screen->set_help_sidebar( 
  120. '<p><strong>' . __( 'For more information:', 'woocommerce-delivery-notes' ) . '</strong></p>'. 
  121. '<p><a href="http://wordpress.org/extend/plugins/woocommerce-delivery-notes/faq/" target="_blank">' . __( 'Frequently Asked Questions', 'woocommerce-delivery-notes' ) . '</a></p>' . 
  122. '<p><a href="http://wordpress.org/support/plugin/woocommerce-delivery-notes" target="_blank">' . __( 'Get Community Support', 'woocommerce-delivery-notes' ) . '</a></p>' . 
  123. '<p><a href="http://wordpress.org/extend/plugins/woocommerce-delivery-notes/" target="_blank">' . __( 'Project on WordPress.org', 'woocommerce-delivery-notes' ) . '</a></p>' . 
  124. '<p><a href="https://github.com/deckerweb/woocommerce-delivery-notes" target="_blank">' . __( 'Project on GitHub', 'woocommerce-delivery-notes' ) . '</a></p>'  
  125. ); 
  126.  
  127. /** 
  128. * Add a tab to the settings page 
  129. */ 
  130. public function add_settings_tab($tabs) { 
  131. $tabs[$this->tab_name] = __( 'Print', 'woocommerce-delivery-notes' ); 
  132.  
  133. return $tabs; 
  134.  
  135. /** 
  136. * Load thumbnail with ajax 
  137. */ 
  138. public function load_thumbnail_ajax() { 
  139. $attachment_id = (int)$_POST['attachment_id'];  
  140.  
  141. // Verify the id 
  142. if( !$attachment_id ) { 
  143. die(); 
  144.  
  145. // create the thumbnail 
  146. $this->create_thumbnail( $attachment_id ); 
  147.  
  148. exit; 
  149.  
  150. /** 
  151. * Create the thumbnail 
  152. */ 
  153. public function create_thumbnail( $attachment_id ) { 
  154. $attachment_src = wp_get_attachment_image_src( $attachment_id, 'full', false ); 
  155.  
  156. // resize the image to a 1/4 of the original size 
  157. // to have a printing point density of about 288ppi. 
  158. ?> 
  159. <img src="<?php echo $attachment_src[0]; ?>" width="<?php echo $attachment_src[1] / 4; ?>" height="<?php echo $attachment_src[2] / 4; ?>" alt="" /> 
  160. <?php 
  161.  
  162. /** 
  163. * Create the settings page content 
  164. */ 
  165. public function create_settings_page() { 
  166. ?> 
  167. <h3><?php _e( 'Invoices and Delivery Notes', 'woocommerce-delivery-notes' ); ?></h3> 
  168. <table class="form-table"> 
  169. <tbody> 
  170. <tr class="hide-if-no-js"> 
  171. <?php 
  172. $attachment_id = get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'company_logo_image_id' ); 
  173. ?> 
  174. <th> 
  175. <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_logo_image_id"><?php _e( 'Company/Shop Logo', 'woocommerce-delivery-notes' ); ?></label> 
  176. </th> 
  177. <td> 
  178. <input id="company-logo-image-id" type="hidden" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_logo_image_id" rows="2" class="regular-text" value="<?php echo $attachment_id ?>" /> 
  179. <span id="company-logo-placeholder"><?php if( !empty( $attachment_id ) ) : ?><?php $this->create_thumbnail( $attachment_id ); ?><?php endif; ?></span> 
  180. <a href="#" id="company-logo-remove-button" <?php if( empty( $attachment_id ) ) : ?>style="display: none;"<?php endif; ?>><?php _e( 'Remove Logo', 'woocommerce-delivery-notes' ); ?></a> 
  181. <a href="#" <?php if( !empty( $attachment_id ) ) : ?>style="display: none;"<?php endif; ?> id="company-logo-add-button"><?php _e( 'Set Logo', 'woocommerce-delivery-notes' ); ?></a> 
  182. <span class="description"> 
  183. <?php _e( 'A company/shop logo representing your business.', 'woocommerce-delivery-notes' ); ?> 
  184. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  185. <?php _e( 'When the image is printed, its pixel density will automatically be eight times higher than the original. This means, 1 printed inch will correspond to about 288 pixels on the screen. Example: an image with a width of 576 pixels and a height of 288 pixels will have a printed size of about 2 inches to 1 inch.', 'woocommerce-delivery-notes' ); ?> 
  186. </span> 
  187. </td> 
  188. </tr> 
  189. <tr> 
  190. <th> 
  191. <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>custom_company_name"><?php _e( 'Company/Shop Name', 'woocommerce-delivery-notes' ); ?></label> 
  192. </th> 
  193. <td> 
  194. <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>custom_company_name" rows="2" class="large-text"><?php echo wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'custom_company_name' ) ); ?></textarea> 
  195. <span class="description"> 
  196. <?php _e( 'Your company/shop name for the Delivery Note.', 'woocommerce-delivery-notes' ); ?> 
  197. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  198. <?php _e( 'Leave blank to use the default Website/ Blog title defined in WordPress settings.', 'woocommerce-delivery-notes' ); ?> 
  199. </span> 
  200. </td> 
  201. </tr> 
  202. <tr> 
  203. <th> 
  204. <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_address"><?php _e( 'Company/Shop Address', 'woocommerce-delivery-notes' ); ?></label> 
  205. </th> 
  206. <td> 
  207. <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_address" rows="5" class="large-text"><?php echo wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'company_address' ) ); ?></textarea> 
  208. <span class="description"> 
  209. <?php _e( 'The postal address of the company/shop, which gets printed right of the company/shop name, above the order listings.', 'woocommerce-delivery-notes' ); ?> 
  210. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  211. <?php _e('Leave blank to not print an address.', 'woocommerce-delivery-notes' ); ?> 
  212. </span> 
  213. </td> 
  214. </tr> 
  215. <tr> 
  216. <th> 
  217. <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>personal_notes"><?php _e( 'Personal Notes', 'woocommerce-delivery-notes' ); ?></label> 
  218. </th> 
  219. <td> 
  220. <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>personal_notes" rows="5" class="large-text"><?php echo wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'personal_notes' ) ); ?></textarea> 
  221. <span class="description"> 
  222. <?php _e( 'Add some personal notes, or season greetings or whatever (e.g. Thank You for Your Order!, Merry Christmas!, etc.).', 'woocommerce-delivery-notes' ); ?> 
  223. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  224. <?php _e('Leave blank to not print any personal notes.', 'woocommerce-delivery-notes' ); ?> 
  225. </span> 
  226. </td> 
  227. </tr> 
  228. <tr> 
  229. <th> 
  230. <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>policies_conditions"><?php _e( 'Returns Policy, Conditions, etc.:', 'woocommerce-delivery-notes' ); ?></label> 
  231. </th> 
  232. <td> 
  233. <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>policies_conditions" rows="5" class="large-text"><?php echo wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'policies_conditions' ) ); ?></textarea> 
  234. <span class="description"> 
  235. <?php _e( 'Here you can add some more policies, conditions etc. For example add a returns policy in case the client would like to send back some goods. In some countries (e.g. in the European Union) this is required so please add any required info in accordance with the statutory regulations.', 'woocommerce-delivery-notes' ); ?> 
  236. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>  
  237. <?php _e('Leave blank to not print any policies or conditions.', 'woocommerce-delivery-notes' ); ?> 
  238. </span> 
  239. </td> 
  240. </tr> 
  241. <tr> 
  242. <th> 
  243. <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>footer_imprint"><?php _e( 'Footer Imprint', 'woocommerce-delivery-notes' ); ?></label> 
  244. </th> 
  245. <td> 
  246. <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>footer_imprint" rows="5" class="large-text"><?php echo wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'footer_imprint' ) ); ?></textarea> 
  247. <span class="description"> 
  248. <?php _e( 'Add some further footer imprint, copyright notes etc. to get the printed sheets a bit more branded to your needs.', 'woocommerce-delivery-notes' ); ?> 
  249. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>  
  250. <?php _e('Leave blank to not print a footer.', 'woocommerce-delivery-notes' ); ?> 
  251. </span> 
  252. </td> 
  253. </tr> 
  254. <tr> 
  255. <th> 
  256. </th> 
  257. <td> 
  258. <?php  
  259. // show template preview links when an order is available  
  260. $args = array( 
  261. 'post_type' => 'shop_order',  
  262. 'posts_per_page' => 1 
  263. ); 
  264. $query = new WP_Query( $args ); 
  265.  
  266. if($query->have_posts()) : ?> 
  267. <?php 
  268. $results = $query->get_posts(); 
  269. $test_id = $results[0]->ID; 
  270. $invoice_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_print_content&template_type=invoice&order_id=' . $test_id ), 'generate_print_content' ); 
  271. $note_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=generate_print_content&template_type=delivery-note&order_id=' . $test_id ), 'generate_print_content' ); 
  272. ?> 
  273. <span class="description"> 
  274. <?php printf( __( 'You can <a href="%1$s" target="%3$s" class="%4$s">preview the invoice template</a> or <a href="%2$s" target="%3$s" class="%4$s">the delivery note template</a>.', 'woocommerce-delivery-notes' ), $invoice_url, $note_url, '_blank', 'print-preview-button' ); ?> 
  275. <?php _e( 'For more advanced control copy <code>woocommerce-delivery-notes/templates/print/style.css</code> to <code>your-theme-name/woocommerce/print/style.css</code>.', 'woocommerce-delivery-notes' ); ?> 
  276. </span> 
  277. <?php endif; ?> 
  278. </td> 
  279. </tr> 
  280. </tbody> 
  281. </table> 
  282. <h3><?php _e( 'Order Numbering Options', 'woocommerce-delivery-notes' ); ?></h3> 
  283. <table class="form-table"> 
  284. <tbody>  
  285. <tr> 
  286. <th> 
  287. <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>order_number_offset"><?php _e( 'Sequential order number', 'woocommerce-delivery-notes' ); ?></label> 
  288. </th> 
  289. <td> 
  290. <?php if( $this->is_woocommerce_sequential_order_numbers_activated() ) : ?> 
  291. <?php _e( 'Sequential numbering is enabled.', 'woocommerce-delivery-notes' ); ?> 
  292. <?php else : ?> 
  293. <?php printf( __( 'Install and activate the free <a href="%s">WooCommerce Sequential Order Numbers</a> Plugin.', 'woocommerce-delivery-notes' ), 'http://wordpress.org/extend/plugins/woocommerce-sequential-order-numbers/' ); ?> 
  294. <?php endif; ?> 
  295. </td> 
  296. </tr> 
  297. </tbody> 
  298. </table> 
  299.  
  300. <input type="hidden" name="<?php echo $this->hidden_submit; ?>" value="submitted"> 
  301. <?php 
  302.  
  303. /** 
  304. * Get the content for an option 
  305. */ 
  306. public function get_setting( $name ) { 
  307. return get_option( WooCommerce_Delivery_Notes::$plugin_prefix . $name ); 
  308.  
  309. /** 
  310. * Save all settings 
  311. */ 
  312. public function save_settings_page() { 
  313. if ( isset( $_POST[ $this->hidden_submit ] ) && $_POST[ $this->hidden_submit ] == 'submitted' ) { 
  314. foreach ( $_POST as $key => $value ) { 
  315. if ( $key != $this->hidden_submit && strpos( $key, WooCommerce_Delivery_Notes::$plugin_prefix ) !== false ) { 
  316. if ( empty( $value ) ) { 
  317. delete_option( $key ); 
  318. } else { 
  319. if ( get_option( $key ) && get_option( $key ) != $value ) { 
  320. update_option( $key, $value ); 
  321. else { 
  322. add_option( $key, $value ); 
  323.