MS_View_Shortcode_Invoice

The Membership 2 MS View Shortcode Invoice class.

Defined (1)

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

/app/view/shortcode/class-ms-view-shortcode-invoice.php  
  1. class MS_View_Shortcode_Invoice extends MS_View { 
  2.  
  3. public function to_html() { 
  4. /** 
  5. * Provide a customized invoice. 
  6. * @since 1.0.0 
  7. */ 
  8. $html = apply_filters( 
  9. 'ms_shortcode_custom_invoice',  
  10. '',  
  11. $this->data 
  12. ); 
  13.  
  14. if ( ! empty( $html ) ) { 
  15. return $html; 
  16. } else { 
  17. $html = ''; 
  18.  
  19. $invoice = $this->data['invoice']; 
  20. $member = $this->data['member']; 
  21. $subscription = $this->data['ms_relationship']; 
  22. $membership = $this->data['membership']; 
  23. $gateway = $this->data['gateway']; 
  24. $is_free = false; 
  25.  
  26. $invoice_number = $invoice->get_invoice_number(); 
  27.  
  28. $inv_title = sprintf( 
  29. '<a href="%s">%s</a>',  
  30. get_permalink( $invoice->id ),  
  31. esc_html( __( 'Invoice ', 'membership2' ) . $invoice_number ) 
  32. ); 
  33.  
  34. if ( $invoice->amount > 0 ) { 
  35. $inv_amount = sprintf( 
  36. '%1$s %2$s',  
  37. $invoice->currency,  
  38. MS_Helper_Billing::format_price( $invoice->amount ) 
  39. ); 
  40. } else { 
  41. $inv_amount = __( 'Free', 'membership2' ); 
  42. $is_free = true; 
  43.  
  44. if ( $invoice->tax ) { 
  45. $inv_taxes = sprintf( 
  46. '%s %s',  
  47. $invoice->currency,  
  48. MS_Helper_Billing::format_price( $invoice->tax ) 
  49. ); 
  50. } else { 
  51. $inv_taxes = ''; 
  52.  
  53. if ( $invoice->discount ) { 
  54. $inv_discount = sprintf( 
  55. '%s -%s',  
  56. $invoice->currency,  
  57. MS_Helper_Billing::format_price( $invoice->discount ) 
  58. ); 
  59. } else { 
  60. $inv_discount = ''; 
  61.  
  62. if ( $invoice->pro_rate ) { 
  63. $inv_pro_rate = sprintf( 
  64. '%s -%s',  
  65. $invoice->currency,  
  66. MS_Helper_Billing::format_price( $invoice->pro_rate ) 
  67. ); 
  68. } else { 
  69. $inv_pro_rate = ''; 
  70.  
  71. $inv_total = sprintf( 
  72. '%s %s',  
  73. $invoice->currency,  
  74. MS_Helper_Billing::format_price( $invoice->total ) 
  75. ); 
  76.  
  77. $inv_title = apply_filters( 'ms_invoice_title', $inv_title, $invoice ); 
  78. $inv_from = apply_filters( 'ms_invoice_sender', MS_Plugin::instance()->settings->invoice_sender_name, $invoice ); 
  79. $inv_to = apply_filters( 'ms_invoice_recipient', $member->username, $invoice, $member ); 
  80. $inv_status = apply_filters( 'ms_invoice_status', $invoice->status_text(), $invoice ); 
  81. $inv_item_name = apply_filters( 'ms_invoice_item_name', $membership->name, $invoice, $membership ); 
  82. $inv_amount = apply_filters( 'ms_invoice_amount', $inv_amount, $invoice ); 
  83. $inv_taxes = apply_filters( 'ms_invoice_taxes', $inv_taxes, $invoice ); 
  84. $inv_discount = apply_filters( 'ms_invoice_discount', $inv_discount, $invoice ); 
  85. $inv_pro_rate = apply_filters( 'ms_invoice_pro_rate', $inv_pro_rate, $invoice ); 
  86. $inv_total = apply_filters( 'ms_invoice_total', $inv_total, $invoice ); 
  87.  
  88. $inv_details = apply_filters( 'ms_invoice_description', $invoice->description, $invoice, null ); 
  89. $inv_date = apply_filters( 
  90. 'ms_invoice_date',  
  91. MS_Helper_Period::format_date( $invoice->invoice_date ),  
  92. $invoice,  
  93. null 
  94. ); 
  95. $inv_due_date = apply_filters( 
  96. 'ms_invoice_due_date',  
  97. MS_Helper_Period::format_date( $invoice->due_date ),  
  98. $invoice,  
  99. null 
  100. ); 
  101.  
  102. if ( $invoice->uses_trial ) { 
  103. $trial_date = apply_filters( 
  104. 'ms_invoice_trial_date',  
  105. MS_Helper_Period::get_period_desc( $membership->trial_period, true ),  
  106. $trial_invoice,  
  107. $invoice 
  108. ); 
  109. $trial_date .= sprintf( 
  110. ' <small>(%s %s)</small>',  
  111. __( 'ends on', 'membership2' ),  
  112. MS_Helper_Period::format_date( $invoice->trial_ends ) 
  113. ); 
  114. } else { 
  115. $trial_date = ''; 
  116.  
  117. ob_start(); 
  118. ?> 
  119. <div class="entry-content ms-invoice" id="invoice"> 
  120. <?php 
  121. /** 
  122. * We hardcode the CSS styles into this file, because the shortcode 
  123. * is also used in Emails, which usually do not load remote CSS 
  124. * files by default... 
  125. */ 
  126. ?> 
  127. <style> 
  128. #invoice table, th, td { margin: 0; font-size: 14px; } 
  129. #invoice table { padding: 0; width: 520px; border: 1px solid #DDD; background-color: #FFF; box-shadow: 0 1px 8px #F0F0F0; } 
  130. #invoice th, td { border: 0; padding: 8px; } 
  131. #invoice th { font-weight: bold; text-align: left; text-transform: none; font-size: 13px; } 
  132. #invoice tr.alt { background-color: #F9F9F9; } 
  133. #invoice tr.sep th,  
  134. #invoice tr.sep td { border-top: 1px solid #DDD; padding-top: 16px; } 
  135. #invoice tr.space th,  
  136. #invoice tr.space td { padding-bottom: 16px; } 
  137. #invoice tr.ms-inv-sep th,  
  138. #invoice tr.ms-inv-sep td { line-height: 1px; height: 1px; padding: 0; border-bottom: 1px solid #DDD; background-color: #F9F9F9; } 
  139. #invoice .ms-inv-total .ms-inv-price { font-weight: bold; font-size: 18px; text-align: right; } 
  140. #invoice h2 { text-align: right; padding: 10px 10px 0 0; } 
  141. #invoice h2 a { color: #000; } 
  142. <?php do_action( 'ms_invoice_css' ) ?> 
  143. </style> 
  144.  
  145. <div class="ms-invoice-details ms-status-<?php echo esc_attr( $invoice->status ); ?>"> 
  146. <table class="ms-purchase-table"> 
  147. <tr class="ms-inv-title"> 
  148. <td colspan="2"><h2><?php echo $inv_title; ?></h2></td> 
  149. </tr> 
  150.  
  151. <?php if ( ! empty( $inv_from ) ) : ?> 
  152. <tr class="ms-inv-from"> 
  153. <th><?php _e( 'Sender', 'membership2' ); ?></th> 
  154. <td class="ms-inv-text"><?php echo $inv_from; ?></td> 
  155. </tr> 
  156. <?php endif; ?> 
  157.  
  158. <tr class="ms-inv-to"> 
  159. <th><?php _e( 'Invoice to', 'membership2' ); ?></th> 
  160. <td class="ms-inv-text"><?php echo $inv_to; ?></td> 
  161. </tr> 
  162. <tr class="ms-inv-invoice-date"> 
  163. <th><?php _e( 'Invoice date', 'membership2' ); ?></th> 
  164. <td class="ms-inv-date"><?php echo $inv_date; ?></td> 
  165. </tr> 
  166. <?php if ( ! empty( $trial_date ) ) : ?> 
  167. <tr class="ms-inv-trial-end-date"> 
  168. <th><?php _e( 'Trial period', 'membership2' ); ?></th> 
  169. <td class="ms-inv-date"><?php echo $trial_date; ?></td> 
  170. </tr> 
  171. <?php endif; ?> 
  172. <tr class="ms-inv-status space"> 
  173. <th><?php _e( 'Status', 'membership2' ); ?></th> 
  174. <td class="ms-inv-text"><?php echo $inv_status; ?></td> 
  175. </tr> 
  176. <tr class="ms-inv-item-name alt sep"> 
  177. <th><?php _e( 'Name', 'membership2' ); ?></th> 
  178. <td class="ms-inv-text"><?php echo $inv_item_name; ?></td> 
  179. </tr> 
  180.  
  181. <?php if ( ! empty( $inv_details ) ) : ?> 
  182. <tr class="ms-inv-description alt"> 
  183. <th><?php _e( 'Description', 'membership2' ); ?></th> 
  184. <td class="ms-inv-text"><?php echo $inv_details; ?></td> 
  185. </tr> 
  186. <?php endif; ?> 
  187.  
  188. <tr class="ms-inv-amount alt space"> 
  189. <th><?php _e( 'Amount', 'membership2' ); ?></th> 
  190. <td class="ms-inv-price"><?php echo $inv_amount; ?></td> 
  191. </tr> 
  192.  
  193. <?php $sep = 'sep'; ?> 
  194.  
  195. <?php if ( ! empty( $inv_discount ) ) : ?> 
  196. <tr class="ms-inv-discount <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  197. <th><?php _e( 'Coupon discount', 'membership2' ); ?></th> 
  198. <td class="ms-inv-price"><?php echo $inv_discount; ?></td> 
  199. </tr> 
  200. <?php endif; ?> 
  201.  
  202. <?php if ( ! empty( $inv_pro_rate ) ) : ?> 
  203. <tr class="ms-inv-pro-rate <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  204. <th><?php _e( 'Pro rate discount', 'membership2' ); ?></th> 
  205. <td class="ms-inv-price"><?php echo $inv_pro_rate; ?></td> 
  206. </tr> 
  207. <?php endif; ?> 
  208.  
  209. <?php if ( ! empty( $inv_taxes ) ) : ?> 
  210. <tr class="ms-inv-tax <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  211. <th><?php 
  212. printf( 
  213. __( 'Taxes %s', 'membership2' ),  
  214. '<small>(' . $invoice->tax_name . ')</small>' 
  215. ); 
  216. ?></th> 
  217. <td class="ms-inv-price"><?php echo $inv_taxes; ?></td> 
  218. </tr> 
  219. <?php endif; ?> 
  220.  
  221. <?php if ( ! $is_free ) : ?> 
  222. <tr class="ms-inv-due-date <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  223. <th><?php _e( 'Payment due', 'membership2' ); ?></th> 
  224. <td class="ms-inv-date"><?php echo $inv_due_date; ?></td> 
  225. </tr> 
  226. <?php endif; ?> 
  227. <tr class="ms-inv-total <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  228. <th><?php _e( 'Total', 'membership2' ); ?></th> 
  229. <td class="ms-inv-price"><?php echo $inv_total; ?></td> 
  230. </tr> 
  231.  
  232. <?php 
  233. $show_button = lib3()->is_true( $this->data['pay_button'] ); 
  234.  
  235. if ( $invoice->is_paid() ) { 
  236. // Invoice is already paid. We don't need a payment 
  237. // button... 
  238. $show_button = false; 
  239.  
  240. if ( $show_button ) { 
  241. ?> 
  242. <tr class="ms-inv-sep sep"><td colspan="2"></td></tr> 
  243. <?php 
  244. do_action( 
  245. 'ms_view_shortcode_invoice_purchase_button',  
  246. $subscription,  
  247. $invoice 
  248. ); 
  249. ?> 
  250. </table> 
  251. </div> 
  252. </div> 
  253. <?php 
  254. $html = ob_get_clean(); 
  255. $html = apply_filters( 'ms_compact_code', $html ); 
  256.  
  257. return apply_filters( 
  258. 'ms_shortcode_invoice',  
  259. $html,  
  260. $this->data 
  261. );