PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / trunk
Subscriptions for WooCommerce with Stripe Recurring Payments vtrunk
1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 All 60 releases
subscription / includes / Admin / Order.php

Order.php in Subscriptions for WooCommerce with Stripe Recurring Payments trunk, at includes/Admin/Order.php

82 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SpringDevs\Subscription\Admin;
4
5 use SpringDevs\Subscription\Illuminate\Helper;
6
7 // HPOS: This file is compatible with WooCommerce High-Performance Order Storage (HPOS).
8 // All WooCommerce order data is accessed via WooCommerce CRUD methods (wc_get_order, etc.).
9 // All direct post meta access is for subscription data only, not WooCommerce order data.
10 // If you add new order data access, use WooCommerce CRUD for HPOS compatibility.
11
12 /**
13 * Order class
14 *
15 * @package SpringDevs\Subscription\Admin
16 */
17 class Order {
18
19 /**
20 * Initialize the class
21 */
22 public function __construct() {
23 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
24 add_action( 'woocommerce_admin_order_data_after_payment_info', array( $this, 'add_subscription_label' ) );
25 }
26
27 /**
28 * Add subscriotion label after order title.
29 *
30 * @param \WC_Order $order Order object.
31 *
32 * @return void
33 */
34 public function add_subscription_label( $order ) {
35 $histories = Helper::get_subscriptions_from_order( $order->get_id() ); // HPOS: Safe, uses custom table for subscription relations.
36 if ( count( $histories ) > 0 ) :
37 ?>
38 <div class="subscrpt-order-label"><?php echo esc_html_e( 'Subscription order', 'subscription' ); ?></div>
39 <?php
40 endif;
41 }
42
43 /**
44 * Related Subscriptions meta box on Orders.
45 */
46 public function add_meta_boxes() {
47 $screen = wps_subscription_is_wc_order_hpos_enabled()
48 ? wc_get_page_screen_id( 'shop-order' )
49 : 'shop_order';
50 $order_id = wps_subscription_is_wc_order_hpos_enabled() && isset( $_GET['id'] ) ? ( sanitize_text_field( wp_unslash( $_GET['id'] ) ) ) : get_the_ID();
51 $histories = Helper::get_subscriptions_from_order( $order_id );
52 if ( is_array( $histories ) ) {
53 $order = wc_get_order( $order_id ); // HPOS: Safe, uses WooCommerce CRUD.
54 add_meta_box(
55 'subscrpt_order_related',
56 __( 'Related Subscriptions', 'subscription' ),
57 array( $this, 'subscrpt_order_related' ),
58 $screen,
59 'normal',
60 'default',
61 array(
62 'histories' => $histories,
63 'order' => $order,
64 )
65 );
66 }
67 }
68
69 /**
70 * Display content related subscriptions.
71 *
72 * @param mixed $order_post Current Order.
73 * @param array $info Meta box Info.
74 */
75 public function subscrpt_order_related( $order_post, $info ) {
76 $histories = $info['args']['histories'];
77 $order = $info['args']['order'];
78
79 include 'views/related-subscriptions.php';
80 }
81 }
82