/includes/class-wcdn-theme.php

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