PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.3.2
Subscriptions for WooCommerce with Stripe Recurring Payments v1.3.2
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.2, at includes/functions.php

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