Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/ecommerce/Invoice.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Invoice class
4
+
*
5
+
* @package TutorPro\Invoice
6
+
* @author Themeum <support@themeum.com>
7
+
* @link https://themeum.com
8
+
* @since 3.0.0
9
+
*/
10
+
11
+
namespace TutorPro\Ecommerce;
12
+
13
+
use Tutor\Ecommerce\OrderController;
14
+
use TUTOR\Input;
15
+
use Tutor\Models\OrderModel;
16
+
use TutorPro\Subscription\Menu;
17
+
/**
18
+
* Invoice class
19
+
*/
20
+
class Invoice {
21
+
22
+
/**
23
+
* Register hooks
24
+
*
25
+
* @since 3.0.0
26
+
*/
27
+
public function __construct() {
28
+
add_action( 'tutor_dashboard_invoice_button', array( $this, 'render_invoice_button' ) );
29
+
add_filter( 'load_dashboard_template_part_from_other_location', array( $this, 'load_invoice_template' ) );
30
+
add_action( 'tutor_after_order_edit_link', array( $this, 'render_admin_order_invoice_button' ) );
31
+
add_action( 'tutor_after_subscription_action_view', array( $this, 'render_admin_order_invoice_button' ) );
32
+
add_filter( 'tutor_order_list_page_template', array( $this, 'load_admin_order_invoice_template' ) );
33
+
}
34
+
35
+
/**
36
+
* Render invoice button.
37
+
*
38
+
* @since 3.0.0
39
+
*
40
+
* @param object $order order.
41
+
*
42
+
* @return void
43
+
*/
44
+
public function render_invoice_button( $order ) {
45
+
if ( self::should_show_invoice( $order ) ) {
46
+
$invoice_url = add_query_arg( 'invoice', $order->id, tutor_utils()->get_tutor_dashboard_page_permalink( 'purchase_history' ) );
47
+
48
+
$is_subscriptions_page = tutor_utils()->is_tutor_frontend_dashboard( 'subscriptions' );
49
+
if ( $is_subscriptions_page ) {
50
+
$invoice_url = add_query_arg( 'subscription', Input::get( 'id' ), $invoice_url );
51
+
}
52
+
53
+
echo '<a href="' . esc_url( $invoice_url ) . '" class="tutor-btn tutor-btn-outline-primary tutor-btn-sm" target="_blank">' .
54
+
esc_html__( 'Invoice', 'tutor-pro' ) .
55
+
'</a>';
56
+
}
57
+
}
58
+
59
+
/**
60
+
* Load invoice templates.
61
+
*
62
+
* @since 3.0.0
63
+
*
64
+
* @param string $template template path.
65
+
*
66
+
* @return string
67
+
*/
68
+
public function load_invoice_template( $template ) {
69
+
$invoice_id = Input::get( 'invoice', 0, Input::TYPE_INT );
70
+
if ( get_query_var( 'tutor_dashboard_page' ) === 'purchase_history' && $invoice_id ) {
71
+
$template = tutor_pro()->path . 'templates/invoice.php';
72
+
if ( file_exists( $template ) ) {
73
+
return $template;
74
+
}
75
+
}
76
+
return $template;
77
+
}
78
+
79
+
/**
80
+
* Render admin invoice button.
81
+
*
82
+
* @since 3.5.0
83
+
*
84
+
* @param object $order order.
85
+
*
86
+
* @return void
87
+
*/
88
+
public function render_admin_order_invoice_button( $order ) {
89
+
if ( self::should_show_invoice( $order ) ) {
90
+
$invoice_url = add_query_arg( 'invoice', $order->id, OrderController::get_order_page_url() );
91
+
92
+
if ( Menu::PAGE_SLUG === Input::get( 'page' ) ) {
93
+
$invoice_url = add_query_arg( 'subscription', Input::get( 'id' ), $invoice_url );
94
+
}
95
+
96
+
echo '<a href="' . esc_url( $invoice_url ) . '" class="tutor-btn tutor-btn-outline-primary tutor-btn-sm" target="_blank">' .
97
+
esc_html__( 'Invoice', 'tutor-pro' ) .
98
+
'</a>';
99
+
}
100
+
}
101
+
102
+
/**
103
+
* Load admin invoice templates.
104
+
*
105
+
* @since 3.0.0
106
+
*
107
+
* @param string $path template path.
108
+
*
109
+
* @return string
110
+
*/
111
+
public function load_admin_order_invoice_template( $path ) {
112
+
$invoice_id = Input::get( 'invoice', 0, Input::TYPE_INT );
113
+
$current_page = Input::get( 'page' );
114
+
115
+
if ( OrderController::PAGE_SLUG === $current_page && $invoice_id ) {
116
+
$template = tutor_pro()->path . 'templates/invoice.php';
117
+
if ( file_exists( $template ) ) {
118
+
return $template;
119
+
}
120
+
}
121
+
122
+
return $path;
123
+
}
124
+
125
+
/**
126
+
* Determine whether to show invoice button.
127
+
*
128
+
* @since 3.0.0
129
+
*
130
+
* @param object $order Order object.
131
+
*
132
+
* @return boolean
133
+
*/
134
+
public static function should_show_invoice( $order ) {
135
+
$status = array( OrderModel::ORDER_COMPLETED );
136
+
return is_object( $order ) && in_array( $order->order_status, $status );
137
+
}
138
+
}
139
+