WooCommerce_Delivery_Notes_Settings

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

Defined (1)

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

/includes/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. // Define default variables 
  11. $this->tab_name = 'woocommerce-delivery-notes'; 
  12. $this->hidden_submit = WooCommerce_Delivery_Notes::$plugin_prefix . 'submit'; 
  13.  
  14. // Load the hooks 
  15. add_action( 'admin_init', array( $this, 'load_admin_hooks' ) ); 
  16.  
  17. /** 
  18. * Load the admin hooks 
  19. */ 
  20. public function load_admin_hooks() {  
  21. add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_tab' ), 100 ); 
  22. add_action( 'woocommerce_settings_tabs_' . $this->tab_name, array( $this, 'create_settings_page' ) ); 
  23. add_action( 'woocommerce_update_options_' . $this->tab_name, array( $this, 'save_settings_page' ) ); 
  24. add_action( 'current_screen', array( $this, 'load_screen_hooks' ) ); 
  25. add_action( 'wp_ajax_load_thumbnail', array( $this, 'load_thumbnail_ajax' ) ); 
  26.  
  27. /** 
  28. * Add the scripts 
  29. */ 
  30. public function load_screen_hooks() { 
  31. $screen = get_current_screen(); 
  32.  
  33. if( $this->is_settings_page() ) { 
  34. add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) ); 
  35. add_action( 'admin_enqueue_scripts', array( $this, 'add_styles' ) ); 
  36.  
  37. /** 
  38. * Add the styles 
  39. */ 
  40. public function add_styles() { 
  41. wp_enqueue_style( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'css/admin.css' ); 
  42.  
  43. /** 
  44. * Add the scripts 
  45. */ 
  46. public function add_scripts() {  
  47. wp_enqueue_media(); 
  48. wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ) ); 
  49. wp_enqueue_script( 'woocommerce-delivery-notes-admin', WooCommerce_Delivery_Notes::$plugin_url . 'js/admin.js', array( 'jquery', 'custom-header', 'woocommerce-delivery-notes-print-link' ) ); 
  50.  
  51. /** 
  52. * Check if we are on settings page 
  53. */ 
  54. public function is_settings_page() { 
  55. if( isset( $_GET['page'] ) && isset( $_GET['tab'] ) && $_GET['tab'] == $this->tab_name ) { 
  56. return true; 
  57. } else { 
  58. return false; 
  59.  
  60. /** 
  61. * Check if sequential order plugin is activated 
  62. */ 
  63. public function is_woocommerce_sequential_order_numbers_activated() { 
  64. if ( in_array( 'woocommerce-sequential-order-numbers/woocommerce-sequential-order-numbers.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 
  65. return true; 
  66. } else { 
  67. return false; 
  68.  
  69. /** 
  70. * Add a tab to the settings page 
  71. */ 
  72. public function add_settings_tab( $tabs ) { 
  73. $tabs[$this->tab_name] = __( 'Print', 'woocommerce-delivery-notes' ); 
  74.  
  75. return $tabs; 
  76.  
  77. /** 
  78. * Load thumbnail with ajax 
  79. */ 
  80. public function load_thumbnail_ajax() { 
  81. $attachment_id = (int)$_POST['attachment_id'];  
  82.  
  83. // Verify the id 
  84. if( !$attachment_id ) { 
  85. die(); 
  86.  
  87. // create the thumbnail 
  88. $this->create_thumbnail( $attachment_id ); 
  89.  
  90. exit; 
  91.  
  92. /** 
  93. * Create the thumbnail 
  94. */ 
  95. public function create_thumbnail( $attachment_id ) { 
  96. $attachment_src = wp_get_attachment_image_src( $attachment_id, 'medium', false ); 
  97.  
  98. ?> 
  99. <img src="<?php echo $attachment_src[0]; ?>" alt="" /> 
  100. <?php 
  101.  
  102. /** 
  103. * Create the settings page content 
  104. */ 
  105. public function create_settings_page() { 
  106. ?> 
  107. <h3><?php _e( 'Print Order', 'woocommerce-delivery-notes' ); ?></h3> 
  108. <p> 
  109. <?php  
  110. // show template preview links when an order is available  
  111. $args = array( 
  112. 'post_type' => 'shop_order',  
  113. 'posts_per_page' => 1 
  114. ); 
  115. $query = new WP_Query( $args ); 
  116.  
  117. if($query->have_posts()) : ?> 
  118. <?php 
  119. $results = $query->get_posts(); 
  120. $test_id = $results[0]->ID; 
  121. $invoice_url = wcdn_get_print_link( $test_id, 'invoice' ); 
  122. $note_url = wcdn_get_print_link( $test_id, 'delivery-note' ); 
  123. ?> 
  124. <input type="hidden" id="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>show_print_preview" /> 
  125. <span class="description"> 
  126. <?php printf( __( 'You can preview the <a href="%1$s" target="%3$s" class="%4$s">invoice template</a> or <a href="%2$s" target="%3$s" class="%4$s">delivery note template</a>.', 'woocommerce-delivery-notes' ), $invoice_url, $note_url, '_blank', '' ); ?> 
  127. <?php _e( 'With the FAQ in the readme file you can learn how to customize the template.', 'woocommerce-delivery-notes' ); ?> 
  128. </span> 
  129. <?php endif; ?> 
  130. </p> 
  131. <table class="form-table"> 
  132. <tbody> 
  133. <tr class="hide-if-no-js"> 
  134. <?php 
  135. $attachment_id = get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'company_logo_image_id' ); 
  136. ?> 
  137. <th> 
  138. <label><?php _e( 'Company/Shop Logo', 'woocommerce-delivery-notes' ); ?></label> 
  139. </th> 
  140. <td> 
  141. <input id="company-logo-image-id" type="hidden" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_logo_image_id" class="regular-text" value="<?php echo $attachment_id ?>" /> 
  142. <div id="company-logo-placeholder"><?php if( !empty( $attachment_id ) ) : ?><?php $this->create_thumbnail( $attachment_id ); ?><?php endif; ?></div> 
  143. <div id="company-logo-buttons"> 
  144. <a href="#" id="company-logo-remove-button" class="button" <?php if( empty( $attachment_id ) ) : ?>style="display: none;"<?php endif; ?>><?php _e( 'Remove Logo', 'woocommerce-delivery-notes' ); ?></a> 
  145. <a href="#" id="company-logo-add-button" class="button" <?php if( !empty( $attachment_id ) ) : ?>style="display: none;"<?php endif; ?> data-uploader-title="<?php echo esc_attr( __( 'Set Logo', 'woocommerce-delivery-notes' ) ); ?>" data-uploader-button-title="<?php echo esc_attr( __( 'Set Logo', 'woocommerce-delivery-notes' ) ); ?>"><?php _e( 'Set Logo', 'woocommerce-delivery-notes' ); ?></a> 
  146. <span id="company-logo-loader" class="spinner"></span> 
  147. </div> 
  148. <span class="description"> 
  149. <?php _e( 'A company/shop logo representing your business.', 'woocommerce-delivery-notes' ); ?> 
  150. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  151. <?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' ); ?> 
  152. </span> 
  153. </td> 
  154. </tr> 
  155. <tr> 
  156. <th> 
  157. <label><?php _e( 'Company/Shop Name', 'woocommerce-delivery-notes' ); ?></label> 
  158. </th> 
  159. <td> 
  160. <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>custom_company_name" class="large-text" value="<?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'custom_company_name' ) ) ); ?>" /> 
  161. <span class="description"> 
  162. <?php _e( 'Your company/shop name for the Delivery Note.', 'woocommerce-delivery-notes' ); ?> 
  163. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  164. <?php _e( 'Leave blank to use the default Website/Blog title defined in WordPress settings. The name will be ignored when a Logo is set.', 'woocommerce-delivery-notes' ); ?> 
  165. </span> 
  166. </td> 
  167. </tr> 
  168. <tr> 
  169. <th> 
  170. <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_address"><?php _e( 'Company/Shop Address', 'woocommerce-delivery-notes' ); ?></label> 
  171. </th> 
  172. <td> 
  173. <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>company_address" rows="5" class="large-text"><?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'company_address' ) ) ); ?></textarea> 
  174. <span class="description"> 
  175. <?php _e( 'The postal address of the company/shop or even e-mail or telephone, which gets printed right after the company/shop name.', 'woocommerce-delivery-notes' ); ?> 
  176. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  177. <?php _e('Leave blank to not print an address.', 'woocommerce-delivery-notes' ); ?> 
  178. </span> 
  179. </td> 
  180. </tr> 
  181. <tr> 
  182. <th> 
  183. <label><?php _e( 'Complimentary Close', 'woocommerce-delivery-notes' ); ?></label> 
  184. </th> 
  185. <td> 
  186. <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>personal_notes" rows="5" class="large-text"><?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'personal_notes' ) ) ); ?></textarea> 
  187. <span class="description"> 
  188. <?php _e( 'Add some personal notes, or season greetings or whatever (e.g. Thank You for Your Order!, Merry Christmas!, etc.).', 'woocommerce-delivery-notes' ); ?> 
  189. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  190. <?php _e('Leave blank to not print any personal notes.', 'woocommerce-delivery-notes' ); ?> 
  191. </span> 
  192. </td> 
  193. </tr> 
  194. <tr> 
  195. <th> 
  196. <label><?php _e( 'Returns Policy, Conditions, etc', 'woocommerce-delivery-notes' ); ?></label> 
  197. </th> 
  198. <td> 
  199. <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>policies_conditions" rows="5" class="large-text"><?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'policies_conditions' ) ) ); ?></textarea> 
  200. <span class="description"> 
  201. <?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' ); ?> 
  202. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>  
  203. <?php _e('Leave blank to not print any policies or conditions.', 'woocommerce-delivery-notes' ); ?> 
  204. </span> 
  205. </td> 
  206. </tr> 
  207. <tr> 
  208. <th> 
  209. <label for="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>footer_imprint"><?php _e( 'Footer', 'woocommerce-delivery-notes' ); ?></label> 
  210. </th> 
  211. <td> 
  212. <textarea name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>footer_imprint" rows="5" class="large-text"><?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'footer_imprint' ) ) ); ?></textarea> 
  213. <span class="description"> 
  214. <?php _e( 'Add some further footer imprint, e-mail, telephone, copyright notes etc. This makes the printed sheets a bit more branded.', 'woocommerce-delivery-notes' ); ?> 
  215. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong>  
  216. <?php _e('Leave blank to not print a footer.', 'woocommerce-delivery-notes' ); ?> 
  217. </span> 
  218. </td> 
  219. </tr> 
  220. </tbody> 
  221. </table> 
  222.  
  223. <h3><?php _e( 'Front-end Options', 'woocommerce-delivery-notes' ); ?></h3> 
  224. <table class="form-table"> 
  225. <tbody>  
  226. <tr> 
  227. <th> 
  228. <label><?php _e( 'Print Page Endpoint', 'woocommerce-delivery-notes' ); ?></label> 
  229. </th> 
  230. <td> 
  231. <p> 
  232. <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_order_page_endpoint" value="<?php echo get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_order_page_endpoint' ); ?>" /> 
  233. </p> 
  234. <span class="description"> 
  235. <?php _e( 'The endpoint is appended to the accounts page URL to print the order. It should be unique.', 'woocommerce-delivery-notes' ); ?> 
  236. </span> 
  237. </td> 
  238. </tr> 
  239. <tr> 
  240. <th> 
  241. <?php _e( 'Print Buttons', 'woocommerce-delivery-notes' ); ?> 
  242. </th> 
  243. <td> 
  244. <fieldset> 
  245. <label> 
  246. <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_button_on_view_order_page" type="hidden" value="" /> 
  247. <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_button_on_view_order_page" type="checkbox" value="1" <?php checked( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_button_on_view_order_page' ), 1 ); ?> /> 
  248. <?php _e( 'Show print button on the "View Order" page', 'woocommerce-delivery-notes' ); ?> 
  249. </label> 
  250. </fieldset> 
  251. <fieldset> 
  252. <label> 
  253. <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_button_on_my_account_page" type="hidden" value="" /> 
  254. <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>print_button_on_my_account_page" type="checkbox" value="1" <?php checked( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_button_on_my_account_page' ), 1 ); ?> /> 
  255. <?php _e( 'Show print buttons on the "My Account" page', 'woocommerce-delivery-notes' ); ?> 
  256. </label> 
  257. </fieldset> 
  258. </td> 
  259. </tr> 
  260. </tbody> 
  261. </table> 
  262.  
  263. <h3><?php _e( 'Order Numbering', 'woocommerce-delivery-notes' ); ?></h3> 
  264. <table class="form-table"> 
  265. <tbody> 
  266. <tr> 
  267. <th> 
  268. <?php _e( 'Invoice Number', 'woocommerce-delivery-notes' ); ?> 
  269. </th> 
  270. <td> 
  271. <p> 
  272. <label> 
  273. <?php $create_invoice_number = get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'create_invoice_number' ); ?> 
  274. <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>create_invoice_number" type="hidden" value="" /> 
  275. <input name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>create_invoice_number" id="create-invoice-number" type="checkbox" value="1" <?php checked( $create_invoice_number, 1 ); ?> /> 
  276. <?php _e( 'Create invoice numbers', 'woocommerce-delivery-notes' ); ?> 
  277. </label> 
  278. </p> 
  279. </td> 
  280. </tr> 
  281. <tr class="invoice-number-row" <?php if( empty( $create_invoice_number ) ) : ?> style="display: none;"<?php endif; ?>> 
  282. <th> 
  283. <label><?php _e( 'Invoice Number Start', 'woocommerce-delivery-notes' ); ?></label> 
  284. </th> 
  285. <td> 
  286. <p> 
  287. <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>invoice_number_start" value="<?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_start', 1 ) ) ); ?>" /> 
  288. </p> 
  289. <span class="description"> 
  290. <?php _e( 'Start the numbering at the specified number.', 'woocommerce-delivery-notes' ); ?> 
  291. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  292. <?php _e( 'Use only integers.', 'woocommerce-delivery-notes' ); ?> 
  293. <?php _e( 'Already created invoice numbers are not affected by changes.', 'woocommerce-delivery-notes' ); ?> 
  294. </span> 
  295. </td> 
  296. </tr> 
  297. <tr class="invoice-number-row" <?php if( empty( $create_invoice_number ) ) : ?> style="display: none;"<?php endif; ?>> 
  298. <th> 
  299. <label><?php _e( 'Invoice Number Prefix', 'woocommerce-delivery-notes' ); ?></label> 
  300. </th> 
  301. <td> 
  302. <p> 
  303. <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>invoice_number_prefix" value="<?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_prefix' ) ) ); ?>" /> 
  304. </p> 
  305. <span class="description"> 
  306. <?php _e( 'This text will be prepended to the invoice number.', 'woocommerce-delivery-notes' ); ?> 
  307. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  308. <?php _e( 'Leave blank to not add a prefix.', 'woocommerce-delivery-notes' ); ?> 
  309. <?php _e( 'Already created invoice numbers are not affected by changes.', 'woocommerce-delivery-notes' ); ?> 
  310. </span> 
  311. </td> 
  312. </tr> 
  313. <tr class="invoice-number-row" <?php if( empty( $create_invoice_number ) ) : ?> style="display: none;"<?php endif; ?>> 
  314. <th> 
  315. <label><?php _e( 'Invoice Number Suffix', 'woocommerce-delivery-notes' ); ?></label> 
  316. </th> 
  317. <td> 
  318. <p> 
  319. <input type="text" name="<?php echo WooCommerce_Delivery_Notes::$plugin_prefix; ?>invoice_number_suffix" value="<?php echo stripslashes( wp_kses_stripslashes( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_suffix' ) ) ); ?>" /> 
  320. </p> 
  321. <span class="description"> 
  322. <?php _e( 'This text will be appended to the invoice number.', 'woocommerce-delivery-notes' ); ?> 
  323. <strong><?php _e( 'Note:', 'woocommerce-delivery-notes' ); ?></strong> 
  324. <?php _e( 'Leave blank to not add a suffix.', 'woocommerce-delivery-notes' ); ?> 
  325. <?php _e( 'Already created invoice numbers are not affected by changes.', 'woocommerce-delivery-notes' ); ?> 
  326. </span> 
  327. </td> 
  328. </tr> 
  329. <tr> 
  330. <th> 
  331. <label><?php _e( 'Sequential Order Number', 'woocommerce-delivery-notes' ); ?></label> 
  332. </th> 
  333. <td> 
  334. <?php if( $this->is_woocommerce_sequential_order_numbers_activated() ) : ?> 
  335. <?php _e( 'Sequential numbering is enabled.', 'woocommerce-delivery-notes' ); ?> 
  336. <?php else : ?> 
  337. <?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/' ); ?> 
  338. <?php endif; ?> 
  339. </td> 
  340. </tr> 
  341. </tbody> 
  342. </table> 
  343.  
  344. <input type="hidden" name="<?php echo $this->hidden_submit; ?>" value="submitted"> 
  345. <?php 
  346.  
  347. /** 
  348. * Save all settings 
  349. */ 
  350. public function save_settings_page() { 
  351. if ( isset( $_POST[ $this->hidden_submit ] ) && $_POST[ $this->hidden_submit ] == 'submitted' ) { 
  352.  
  353. // Save settings 
  354. foreach ( $_POST as $key => $value ) { 
  355. if ( $key != $this->hidden_submit && strpos( $key, WooCommerce_Delivery_Notes::$plugin_prefix ) !== false ) { 
  356. // Set a default values 
  357. if ( empty( $value ) ) { 
  358. if ( $key == WooCommerce_Delivery_Notes::$plugin_prefix . 'print_order_page_endpoint' ) { 
  359. $value = 'print-order'; 
  360.  
  361. if ( $key == WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_start' ) { 
  362. $value = 1; 
  363.  
  364. // Sanitize values 
  365. if ( $key == WooCommerce_Delivery_Notes::$plugin_prefix . 'print_order_page_endpoint' ) { 
  366. $value = sanitize_title( $value ); 
  367.  
  368. if ( $key == WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_start' ) { 
  369. if ( !ctype_digit( $value ) ) { 
  370. $value = 1; 
  371.  
  372. // Check if the counter should be reset 
  373. if( get_option( $key ) != $value ) { 
  374. update_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'invoice_number_counter', 0 ); 
  375.  
  376.  
  377. // Update the value 
  378. if ( empty( $value ) ) { 
  379. delete_option( $key ); 
  380. } else { 
  381. if ( get_option( $key ) && get_option( $key ) != $value ) { 
  382. update_option( $key, $value ); 
  383. else { 
  384. add_option( $key, $value ); 
  385.  
  386. // Flush permalink structs with  
  387. set_transient( WooCommerce_Delivery_Notes::$plugin_prefix . 'flush_rewrite_rules', true ); 
  388.