WooCommerce_Delivery_Notes_Theme

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

Defined (1)

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

/includes/class-wcdn-theme.php  
  1. class WooCommerce_Delivery_Notes_Theme { 
  2.  
  3. public $template_type; 
  4.  
  5. /** 
  6. * Constructor 
  7. */ 
  8. public function __construct() {  
  9. // Load the hooks 
  10. add_action( 'wp_loaded', array( $this, 'load_hooks' ) ); 
  11.  
  12. /** 
  13. * Load the hooks at the end when  
  14. * the theme and plugins are ready. 
  15. */ 
  16. public function load_hooks() {  
  17. // Define defaults 
  18. $this->template_type = apply_filters( 'wcdn_theme_print_button_template_type', 'invoice' ); 
  19.  
  20. // hooks 
  21. add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'create_print_button_account_page' ), 10, 2 ); 
  22. add_action( 'woocommerce_view_order', array( $this, 'create_print_button_order_page' ) ); 
  23. add_action( 'woocommerce_thankyou', array( $this, 'create_print_button_order_page' ) ); 
  24. add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) ); 
  25.  
  26. /** 
  27. * Add the scripts 
  28. */ 
  29. public function add_scripts() { 
  30. if ( is_account_page() || is_order_received_page() || $this->is_woocommerce_tracking_page() ) { 
  31. wp_enqueue_script( 'woocommerce-delivery-notes-print-link', WooCommerce_Delivery_Notes::$plugin_url . 'js/jquery.print-link.js', array( 'jquery' ) ); 
  32. wp_enqueue_script( 'woocommerce-delivery-notes-theme', WooCommerce_Delivery_Notes::$plugin_url . 'js/theme.js', array( 'jquery', 'woocommerce-delivery-notes-print-link' ) ); 
  33. }  
  34.  
  35. /** 
  36. * Create a print button for the 'My Account' page 
  37. */ 
  38. public function create_print_button_account_page( $actions, $order ) {  
  39. if( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_button_on_my_account_page' ) ) { 
  40. $actions['print'] = array( 
  41. 'url' => wcdn_get_print_link( $order->id, $this->template_type ),  
  42. 'name' => __( 'Print', 'woocommerce-delivery-notes' ) 
  43. ); 
  44. }  
  45. return $actions; 
  46.  
  47. /** 
  48. * Create a print button for the 'View Order' page 
  49. */ 
  50. public function create_print_button_order_page( $order_id ) {  
  51. if( get_option( WooCommerce_Delivery_Notes::$plugin_prefix . 'print_button_on_view_order_page' ) ) { 
  52. $print_url = wcdn_get_print_link( $order_id, $this->template_type ); 
  53.  
  54. // use a different url for the tracking page 
  55. if( $this->is_woocommerce_tracking_page() ) { 
  56. $print_url = wcdn_get_print_link( $order_id, $this->template_type, $_REQUEST['order_email'] ); 
  57. ?> 
  58. <p class="order-print"> 
  59. <a href="<?php echo $print_url; ?>" class="button print"><?php _e( 'Print', 'woocommerce-delivery-notes' ); ?></a> 
  60. </p> 
  61. <?php 
  62.  
  63. /** 
  64. * Is WooCommerce 'Order Tracking' page 
  65. */ 
  66. public function is_woocommerce_tracking_page() { 
  67. return ( is_page( wc_get_page_id( 'order_tracking' ) ) && isset( $_REQUEST['order_email'] ) ) ? true : false; 
  68.