PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.3.0
Subscriptions for WooCommerce with Stripe Recurring Payments v1.3.0
2.0.0 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 All 61 releases
subscription / includes / functions.php

functions.php in Subscriptions for WooCommerce with Stripe Recurring Payments 1.3.0, at includes/functions.php

170 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
4
5 /**
6 * Generate Url for Subscription Action.
7 *
8 * @param string $action Action.
9 * @param string $nonce nonce.
10 * @param int $subscription_id Subscription ID.
11 *
12 * @return string
13 */
14 function subscrpt_get_action_url( $action, $nonce, $subscription_id ) {
15 return add_query_arg(
16 array(
17 'subscrpt_id' => $subscription_id,
18 'action' => $action,
19 'wpnonce' => $nonce,
20 ),
21 wc_get_endpoint_url( 'view-subscription', $subscription_id, wc_get_page_permalink( 'myaccount' ) )
22 );
23 }
24
25
26 function subscrpt_get_typos( $number, $typo ) {
27 if ( $number == 1 && $typo == 'days' ) {
28 return __( 'day', 'sdevs_subscrpt' );
29 } elseif ( $number == 1 && $typo == 'weeks' ) {
30 return __( 'week', 'sdevs_subscrpt' );
31 } elseif ( $number == 1 && $typo == 'months' ) {
32 return __( 'month', 'sdevs_subscrpt' );
33 } elseif ( $number == 1 && $typo == 'years' ) {
34 return __( 'year', 'sdevs_subscrpt' );
35 } else {
36 return $typo;
37 }
38 }
39
40 /**
41 * Format time with trial.
42 *
43 * @param mixed $time Time.
44 * @param null|string $trial Trial.
45 *
46 * @return string
47 */
48 function subscrpt_next_date( $time, $trial = null ) {
49 if ( null === $trial ) {
50 $start_date = time();
51 } else {
52 $start_date = strtotime( $trial );
53 }
54
55 return gmdate( 'F d, Y', strtotime( $time, $start_date ) );
56 }
57
58 /**
59 * Check if subscription-pro activated.
60 *
61 * @return bool
62 */
63 function subscrpt_pro_activated(): bool {
64 return class_exists( 'Sdevs_Wc_Subscription_Pro' );
65 }
66
67 /**
68 * Get renewal process settings.
69 *
70 * @return bool
71 */
72 function subscrpt_is_auto_renew_enabled() {
73 return 'auto' === get_option( 'subscrpt_renewal_process', 'auto' );
74 }
75
76 /**
77 * Return Label against key.
78 *
79 * @param string $key Key to return cast Value.
80 *
81 * @return string
82 */
83 function order_relation_type_cast( string $key ) {
84 $relational_type_keys = apply_filters(
85 'subscrpt_order_relational_types',
86 array(
87 'new' => __( 'New Subscription Order', 'sdevs_subscrpt' ),
88 'renew' => __( 'Renewal Order', 'sdevs_subscrpt' ),
89 )
90 );
91
92 return isset( $relational_type_keys[ $key ] ) ? $relational_type_keys[ $key ] : '-';
93 }
94
95 if ( ! function_exists( 'is_wc_order_hpos_enabled' ) ) {
96 /**
97 * Check if HPOS enabled.
98 */
99 function is_wc_order_hpos_enabled() {
100 return function_exists( 'wc_get_container' ) ?
101 wc_get_container()
102 ->get( CustomOrdersTableController::class )
103 ->custom_orders_table_usage_is_enabled()
104 : false;
105 }
106 }
107
108 if ( ! function_exists( 'sdevs_wp_strtotime' ) ) {
109 /**
110 * Get strtotime with WordPress timezone config.
111 *
112 * @param string $str string.
113 * @param int|null $base_timestamp base timestamp.
114 *
115 * @return int
116 */
117 function sdevs_wp_strtotime( $str, $base_timestamp = null ) {
118 return strtotime( wp_date( 'Y-m-d H:i:s', strtotime( $str, $base_timestamp ) ) );
119 }
120 }
121
122 if ( ! function_exists( 'sdevs_order_status_label' ) ) {
123 /**
124 * Get order status label from slug.
125 *
126 * @param string $status Status.
127 *
128 * @return string
129 */
130 function sdevs_order_status_label( $status ) {
131 $order_statuses = wc_get_order_statuses();
132 return ( isset( $order_statuses[ "wc-{$status}" ] ) ? $order_statuses[ "wc-{$status}" ] : $status );
133 }
134 }
135
136 if ( ! function_exists( 'get_timing_types' ) ) {
137 /**
138 * Get labels.
139 *
140 * @param bool $key_value key_value.
141 *
142 * @return array
143 */
144 function get_timing_types( $key_value = false ): array {
145 return $key_value ? array(
146 'days' => 'Daily',
147 'weeks' => 'Weekly',
148 'months' => 'Monthly',
149 'years' => 'Yearly',
150 ) : array(
151 array(
152 'label' => __( 'day(s)', 'sdevs_subscrpt' ),
153 'value' => 'days',
154 ),
155 array(
156 'label' => __( 'week(s)', 'sdevs_subscrpt' ),
157 'value' => 'weeks',
158 ),
159 array(
160 'label' => __( 'month(s)', 'sdevs_subscrpt' ),
161 'value' => 'months',
162 ),
163 array(
164 'label' => __( 'year(s)', 'sdevs_subscrpt' ),
165 'value' => 'years',
166 ),
167 );
168 }
169 }
170