Changeset 3083564
- Timestamp:
- 05/08/2024 09:00:08 PM (22 months ago)
- Location:
- subscription/trunk
- Files:
-
- 18 edited
-
includes/Admin/Order.php (modified) (2 diffs)
-
includes/Admin/Subscriptions.php (modified) (2 diffs)
-
includes/Admin/views/order-history.php (modified) (1 diff)
-
includes/Admin/views/subscription-customer.php (modified) (1 diff)
-
includes/Admin/views/subscription-order-info.php (modified) (1 diff)
-
includes/Frontend/Checkout.php (modified) (5 diffs)
-
includes/Frontend/MyAccount.php (modified) (10 diffs)
-
includes/Frontend/Product.php (modified) (1 diff)
-
includes/Illuminate/Action.php (modified) (15 diffs)
-
includes/Illuminate/Cron.php (modified) (2 diffs)
-
includes/Illuminate/Helper.php (modified) (2 diffs)
-
includes/Illuminate/Order.php (modified) (2 diffs)
-
includes/Illuminate/Post.php (modified) (1 diff)
-
includes/functions.php (modified) (7 diffs)
-
readme.txt (modified) (3 diffs)
-
subscription.php (modified) (2 diffs)
-
templates/myaccount/single.php (modified) (2 diffs)
-
vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
subscription/trunk/includes/Admin/Order.php
r2927437 r3083564 23 23 */ 24 24 public function add_meta_boxes() { 25 $order_id = get_the_ID(); 25 $screen = is_wc_order_hpos_enabled() 26 ? wc_get_page_screen_id( 'shop-order' ) 27 : 'shop_order'; 28 $order_id = is_wc_order_hpos_enabled() && isset( $_GET['id'] ) ? ( sanitize_text_field( wp_unslash( $_GET['id'] ) ) ) : get_the_ID(); 26 29 $histories = Helper::get_subscriptions_from_order( $order_id ); 27 30 if ( is_array( $histories ) ) { … … 31 34 __( 'Related Subscriptions', 'sdevs_subscrpt' ), 32 35 array( $this, 'subscrpt_order_related' ), 33 'shop_order',36 $screen, 34 37 'normal', 35 38 'default', -
subscription/trunk/includes/Admin/Subscriptions.php
r2927437 r3083564 219 219 } 220 220 221 /** 222 * Display subscription info. 223 * 224 * @return void 225 */ 221 226 public function subscrpt_order_info() { 222 227 $post_meta = get_post_meta( get_the_ID(), '_order_subscrpt_meta', true ); … … 282 287 283 288 $post_meta = get_post_meta( $post_id, '_order_subscrpt_meta', true ); 284 if ( $action === 'active') {289 if ( 'active' === $action ) { 285 290 $order = wc_get_order( $post_meta['order_id'] ); 286 291 $order->update_status( 'completed' ); 287 } 288 289 Action::status( $action, $post_id ); 292 Action::status( $action, $post_id, false ); 293 } else { 294 Action::status( $action, $post_id ); 295 } 290 296 } 291 297 } -
subscription/trunk/includes/Admin/views/order-history.php
r2927437 r3083564 20 20 ?> 21 21 <tr> 22 <td><a href="<?php echo wp_kses_post( get_edit_post_link( $order_history->order_id) ); ?>" target="_blank"><?php echo wp_kses_post( $order_history->order_id ); ?></a></td>22 <td><a href="<?php echo wp_kses_post( $order->get_edit_order_url() ); ?>" target="_blank"><?php echo wp_kses_post( $order_history->order_id ); ?></a></td> 23 23 <td><?php echo wp_kses_post( order_relation_type_cast( $order_history->type ) ); ?></td> 24 24 <td> -
subscription/trunk/includes/Admin/views/subscription-customer.php
r2797349 r3083564 20 20 <tr class="view"> 21 21 <th> </th> 22 <td><a class="button button-small" target="_blank" href="<?php echo esc_html( get_edit_post_link( $post_meta['order_id']) ); ?>">View Order</a></td>22 <td><a class="button button-small" target="_blank" href="<?php echo esc_html( $order->get_edit_order_url() ); ?>">View Order</a></td> 23 23 </tr> 24 24 </tbody> -
subscription/trunk/includes/Admin/views/subscription-order-info.php
r2927437 r3083564 48 48 <td><?php echo esc_html( $order->get_payment_method_title() ); ?></td> 49 49 </tr> 50 <?php if ( class_exists( 'WC_Stripe' ) && 'stripe' === $order->get_payment_method() ) : ?> 51 <tr> 52 <?php 53 $is_auto_renew = get_post_meta( get_the_ID(), '_subscrpt_auto_renew', true ); 54 ?> 55 <th scope="row">Stripe Auto Renewal:</th> 56 <td> 57 <?php echo esc_html( '0' !== $is_auto_renew ? 'On' : 'Off' ); ?> 58 </td> 59 </tr> 60 <?php endif; ?> 50 61 <tr> 51 62 <th scope="row">Billing:</th> 52 <td><?php echo wp_kses_post( $order->get_formatted_billing_address() ); ?></td>63 <td><?php echo wp_kses_post( $order->get_formatted_billing_address() ? $order->get_formatted_billing_address() : 'No billing address set.' ); ?></td> 53 64 </tr> 54 65 <tr> -
subscription/trunk/includes/Frontend/Checkout.php
r2927437 r3083564 16 16 public function __construct() { 17 17 add_action( 'woocommerce_checkout_order_processed', array( $this, 'create_subscription_after_checkout' ) ); 18 add_action( 'woocommerce_resume_order', array( $this, 'remove_subscriptions' ) ); 18 19 } 19 20 … … 63 64 if ( ! empty( $post_meta['trial_time'] ) && $post_meta['trial_time'] > 0 && ! $is_renew && $has_trial ) { 64 65 $trial = $post_meta['trial_time'] . ' ' . Helper::get_typos( $post_meta['trial_time'], $post_meta['trial_type'] ); 65 $start_date = s trtotime( $trial );66 $start_date = sdevs_wp_strtotime( $trial ); 66 67 } 67 68 68 $order_item_meta = array( 69 69 'order_id' => $order_id, … … 71 71 'trial' => $trial, 72 72 'start_date' => $start_date, 73 'next_date' => s trtotime( $post_meta['time'] . ' ' . $type, $start_date ),73 'next_date' => sdevs_wp_strtotime( $post_meta['time'] . ' ' . $type, $start_date ), 74 74 ); 75 75 … … 88 88 // Renew subscription if need! 89 89 $renew_subscription_id = Helper::subscription_exists( $product->get_id(), 'expired' ); 90 if ( $is_renew && $renew_subscription_id && $post_status !== 'cancelled') {90 if ( $is_renew && $renew_subscription_id && 'cancelled' !== $post_status ) { 91 91 $comment_id = wp_insert_comment( 92 92 array( 93 93 'comment_author' => 'Subscription for WooCommerce', 94 'comment_content' => sprintf( __( 'The order %s has been created for the subscription', 'sdevs_subscrpt' ), $order_id ), 94 'comment_content' => sprintf( 95 // translators: order id. 96 __( 'The order %s has been created for the subscription', 'sdevs_subscrpt' ), 97 $order_id 98 ), 95 99 'comment_post_ID' => $renew_subscription_id, 96 100 'comment_type' => 'order_note', … … 154 158 } 155 159 } 160 161 /** 162 * Remove subscriptions for resumed orders. 163 * 164 * @param int $order_id Order id. 165 * 166 * @return void 167 */ 168 public function remove_subscriptions( $order_id ) { 169 global $wpdb; 170 // delete subscriptions & order item meta. 171 $histories = Helper::get_subscriptions_from_order( $order_id ); 172 foreach ( $histories as $history ) { 173 $table_name = $wpdb->prefix . 'subscrpt_order_relation'; 174 // @phpcs:ignore 175 $relation_count = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i WHERE subscription_id=%d', array( $table_name, $history->subscription_id ) ) ); 176 if ( 1 === (int) $relation_count ) { 177 wp_delete_post( $history->subscription_id, true ); 178 } 179 wc_delete_order_item_meta( $history->order_item_id, '_subscrpt_meta' ); 180 } 181 182 // delete order subscription relation. 183 global $wpdb; 184 $table_name = $wpdb->prefix . 'subscrpt_order_relation'; 185 // phpcs:ignore 186 $wpdb->delete( $table_name, array( 'order_id' => $order_id ), array( '%d' ) ); 187 } 156 188 } -
subscription/trunk/includes/Frontend/MyAccount.php
r2927437 r3083564 8 8 * @package SpringDevs\Subscription\Frontend 9 9 */ 10 class MyAccount 11 { 10 class MyAccount { 11 12 12 13 13 /** 14 14 * Initialize the class 15 15 */ 16 public function __construct() 17 { 18 add_action('init', array($this, 'flush_rewrite_rules')); 19 add_filter('woocommerce_account_menu_items', array($this, 'custom_my_account_menu_items')); 20 add_filter('woocommerce_endpoint_view-subscription_title', array($this, 'change_single_title')); 21 add_filter('the_title', array($this, 'change_lists_title'), 10); 22 add_filter('woocommerce_get_query_vars', array($this, 'custom_query_vars')); 23 add_action('woocommerce_account_view-subscription_endpoint', array($this, 'view_subscrpt_content')); 24 add_action('woocommerce_account_subscriptions_endpoint', array($this, 'subscrpt_endpoint_content')); 25 add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); 16 public function __construct() { 17 add_action( 'init', array( $this, 'flush_rewrite_rules' ) ); 18 add_filter( 'woocommerce_account_menu_items', array( $this, 'custom_my_account_menu_items' ) ); 19 add_filter( 'woocommerce_endpoint_view-subscription_title', array( $this, 'change_single_title' ) ); 20 add_filter( 'the_title', array( $this, 'change_lists_title' ), 10 ); 21 add_filter( 'woocommerce_get_query_vars', array( $this, 'custom_query_vars' ) ); 22 add_action( 'woocommerce_account_view-subscription_endpoint', array( $this, 'view_subscrpt_content' ) ); 23 add_action( 'woocommerce_account_subscriptions_endpoint', array( $this, 'subscrpt_endpoint_content' ) ); 24 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); 26 25 } 27 26 … … 33 32 * @return array 34 33 */ 35 public function custom_query_vars(array $query_vars): array 36 { 34 public function custom_query_vars( array $query_vars ): array { 37 35 $query_vars['view-subscription'] = 'view-subscription'; 38 36 return $query_vars; … … 44 42 * @param Int $id Post ID. 45 43 */ 46 public function view_subscrpt_content(int $id) 47 { 48 $post_meta = get_post_meta($id, '_order_subscrpt_meta', true); 49 $order = wc_get_order($post_meta['order_id']); 50 $order_item = $order->get_item($post_meta['order_item_id']); 51 $status = get_post_status($id); 52 $user_cancel = get_post_meta($id, '_subscrpt_user_cancel', true); 44 public function view_subscrpt_content( int $id ) { 45 $post_meta = get_post_meta( $id, '_order_subscrpt_meta', true ); 46 $order = wc_get_order( $post_meta['order_id'] ); 47 $order_item = $order->get_item( $post_meta['order_item_id'] ); 48 $status = get_post_status( $id ); 49 $user_cancel = get_post_meta( $id, '_subscrpt_user_cancel', true ); 53 50 54 $subscrpt_nonce = wp_create_nonce( 'subscrpt_nonce');51 $subscrpt_nonce = wp_create_nonce( 'subscrpt_nonce' ); 55 52 $action_buttons = array(); 56 53 57 if ( 'cancelled' !== $status) {58 if ( in_array($status, array('pending', 'active', 'on_hold'), true) && 'yes' === $user_cancel) {54 if ( 'cancelled' !== $status ) { 55 if ( in_array( $status, array( 'pending', 'active', 'on_hold' ), true ) && 'yes' === $user_cancel ) { 59 56 $action_buttons['cancel'] = array( 60 'url' => subscrpt_get_action_url( 'cancelled', $subscrpt_nonce, $id),61 'label' => __( 'Cancel', 'sdevs_subscrpt'),57 'url' => subscrpt_get_action_url( 'cancelled', $subscrpt_nonce, $id ), 58 'label' => __( 'Cancel', 'sdevs_subscrpt' ), 62 59 'class' => 'cancel', 63 60 ); 64 } elseif ( trim($status) === trim('pe_cancelled')) {61 } elseif ( trim( $status ) === trim( 'pe_cancelled' ) ) { 65 62 $action_buttons['reactive'] = array( 66 'url' => subscrpt_get_action_url( 'reactive', $subscrpt_nonce, $id),67 'label' => __( 'Reactive', 'sdevs_subscrpt'),63 'url' => subscrpt_get_action_url( 'reactive', $subscrpt_nonce, $id ), 64 'label' => __( 'Reactive', 'sdevs_subscrpt' ), 68 65 ); 69 } elseif ( 'expired' === $status && 'pending' !== $order->get_status()) {66 } elseif ( 'expired' === $status && 'pending' !== $order->get_status() ) { 70 67 $action_buttons['renew'] = array( 71 'url' => subscrpt_get_action_url( 'renew', $subscrpt_nonce, $id),72 'label' => __( 'Renew', 'sdevs_subscrpt'),68 'url' => subscrpt_get_action_url( 'renew', $subscrpt_nonce, $id ), 69 'label' => __( 'Renew', 'sdevs_subscrpt' ), 73 70 ); 74 71 } 75 72 76 if ( 'pending' === $order->get_status()) {73 if ( 'pending' === $order->get_status() ) { 77 74 $action_buttons['pay_now'] = array( 78 75 'url' => $order->get_checkout_payment_url(), 79 'label' => __( 'Pay now', 'sdevs_subscrpt'),76 'label' => __( 'Pay now', 'sdevs_subscrpt' ), 80 77 ); 81 78 } 82 79 } 83 80 84 $post_status_object = get_post_status_object( $status);85 $action_buttons = apply_filters( 'subscrpt_single_action_buttons', $action_buttons, $id, $subscrpt_nonce, $status);81 $post_status_object = get_post_status_object( $status ); 82 $action_buttons = apply_filters( 'subscrpt_single_action_buttons', $action_buttons, $id, $subscrpt_nonce, $status ); 86 83 87 84 wc_get_template( … … 95 92 'user_cancel' => $user_cancel, 96 93 'action_buttons' => $action_buttons, 97 'wp_button_class' => wc_wp_theme_get_element_class_name( 'button') ? ' ' . wc_wp_theme_get_element_class_name('button') : '',94 'wp_button_class' => wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '', 98 95 ), 99 96 'subscription', … … 105 102 * Re-write flush 106 103 */ 107 public function flush_rewrite_rules() 108 { 109 add_rewrite_endpoint('subscriptions', EP_ROOT | EP_PAGES); 104 public function flush_rewrite_rules() { 105 add_rewrite_endpoint( 'subscriptions', EP_ROOT | EP_PAGES ); 110 106 flush_rewrite_rules(); 111 107 } … … 118 114 * @return String 119 115 */ 120 public function change_single_title(string $title): string 121 { 116 public function change_single_title( string $title ): string { 122 117 /* translators: %s: Subscription ID */ 123 return sprintf( __('Subscription #%s', 'sdevs_subscrpt'), get_query_var('view-subscription'));118 return sprintf( __( 'Subscription #%s', 'sdevs_subscrpt' ), get_query_var( 'view-subscription' ) ); 124 119 } 125 120 … … 131 126 * @return String 132 127 */ 133 public function change_lists_title(string $title): string 134 { 128 public function change_lists_title( string $title ): string { 135 129 global $wp_query; 136 $is_endpoint = isset( $wp_query->query_vars['subscriptions']);137 if ( $is_endpoint && !is_admin() && is_account_page()) {138 $title = __( 'My Subscriptions', 'sdevs_subscrpt');130 $is_endpoint = isset( $wp_query->query_vars['subscriptions'] ); 131 if ( $is_endpoint && ! is_admin() && is_account_page() ) { 132 $title = __( 'My Subscriptions', 'sdevs_subscrpt' ); 139 133 } 140 134 return $title; … … 147 141 * @return array 148 142 */ 149 public function custom_my_account_menu_items(array $items): array 150 { 143 public function custom_my_account_menu_items( array $items ): array { 151 144 $logout = $items['customer-logout']; 152 unset( $items['customer-logout']);153 $items['subscriptions'] = __( 'Subscriptions', 'sdevs_subscrpt');145 unset( $items['customer-logout'] ); 146 $items['subscriptions'] = __( 'Subscriptions', 'sdevs_subscrpt' ); 154 147 $items['customer-logout'] = $logout; 155 148 return $items; … … 159 152 * Subscription Single EndPoint Content 160 153 */ 161 public function subscrpt_endpoint_content() 162 { 154 public function subscrpt_endpoint_content() { 163 155 wc_get_template( 164 156 'myaccount/subscriptions.php', 165 157 array( 166 'wp_button_class' => wc_wp_theme_get_element_class_name( 'button') ? ' ' . wc_wp_theme_get_element_class_name('button') : '',158 'wp_button_class' => wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '', 167 159 ), 168 160 'subscription', … … 174 166 * Enqueue assets 175 167 */ 176 public function enqueue_styles() 177 { 178 wp_enqueue_style('subscrpt_status_css'); 168 public function enqueue_styles() { 169 wp_enqueue_style( 'subscrpt_status_css' ); 179 170 } 180 171 } -
subscription/trunk/includes/Frontend/Product.php
r3070491 r3083564 242 242 } 243 243 } 244 $price_html = $price . ' /' . $time . $type . $signup_fee_html . $trial;244 $price_html = $price . ' / ' . $time . $type . $signup_fee_html . $trial; 245 245 return $price_html; 246 246 else : -
subscription/trunk/includes/Illuminate/Action.php
r2927437 r3083564 8 8 * @package SpringDevs\Subscription\Illuminate 9 9 */ 10 class Action 11 { 10 class Action { 11 12 12 13 13 /** … … 16 16 * @param string $status Status. 17 17 * @param Int $subscription_id Subscription ID. 18 * @param bool $write_comment Write comment?. 18 19 */ 19 public static function status(string $status, int $subscription_id) 20 { 21 // if (current_user_can('edit_post', $subscription_id)) { 20 public static function status( string $status, int $subscription_id, bool $write_comment = true ) { 22 21 wp_update_post( 23 22 array( … … 27 26 ); 28 27 29 self::write_comment($status, $subscription_id); 30 self::user($subscription_id); 31 // } 28 if ( $write_comment ) { 29 self::write_comment( $status, $subscription_id ); 30 } 31 32 self::user( $subscription_id ); 32 33 } 33 34 … … 38 39 * @param Int $subscription_id Subscription ID. 39 40 */ 40 public static function write_comment(string $status, int $subscription_id) 41 { 42 switch ($status) { 41 public static function write_comment( string $status, int $subscription_id ) { 42 switch ( $status ) { 43 43 case 'expired': 44 self::expired( $subscription_id);44 self::expired( $subscription_id ); 45 45 break; 46 46 case 'active': 47 self::active( $subscription_id);47 self::active( $subscription_id ); 48 48 break; 49 49 case 'pending': 50 self::pending( $subscription_id);50 self::pending( $subscription_id ); 51 51 break; 52 52 case 'cancelled': 53 self::cancelled( $subscription_id);53 self::cancelled( $subscription_id ); 54 54 break; 55 55 case 'pe_cancelled': 56 self::pe_cancelled( $subscription_id);56 self::pe_cancelled( $subscription_id ); 57 57 break; 58 58 } … … 64 64 * @param int $subscription_id Subscription ID. 65 65 */ 66 private static function expired(int $subscription_id) 67 { 66 private static function expired( int $subscription_id ) { 68 67 $comment_id = wp_insert_comment( 69 68 array( … … 74 73 ) 75 74 ); 76 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Expired');75 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Expired' ); 77 76 78 do_action( 'subscrpt_subscription_expired', $subscription_id);77 do_action( 'subscrpt_subscription_expired', $subscription_id ); 79 78 } 80 79 … … 84 83 * @param int $subscription_id Subscription ID. 85 84 */ 86 private static function active(int $subscription_id) 87 { 85 private static function active( int $subscription_id ) { 88 86 $comment_id = wp_insert_comment( 89 87 array( … … 94 92 ) 95 93 ); 96 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Activated');94 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Activated' ); 97 95 98 do_action( 'subscrpt_subscription_activated', $subscription_id);96 do_action( 'subscrpt_subscription_activated', $subscription_id ); 99 97 } 100 98 … … 104 102 * @param int $subscription_id Subscription ID. 105 103 */ 106 private static function pending(int $subscription_id) 107 { 104 private static function pending( int $subscription_id ) { 108 105 $comment_id = wp_insert_comment( 109 106 array( … … 114 111 ) 115 112 ); 116 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Pending');113 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Pending' ); 117 114 } 118 115 … … 122 119 * @param int $subscription_id Subscription ID. 123 120 */ 124 private static function cancelled(int $subscription_id) 125 { 121 private static function cancelled( int $subscription_id ) { 126 122 $comment_id = wp_insert_comment( 127 123 array( … … 132 128 ) 133 129 ); 134 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Cancelled');130 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Cancelled' ); 135 131 } 136 132 … … 140 136 * @param int $subscription_id Subscription ID. 141 137 */ 142 private static function pe_cancelled(int $subscription_id) 143 { 138 private static function pe_cancelled( int $subscription_id ) { 144 139 $comment_id = wp_insert_comment( 145 140 array( … … 150 145 ) 151 146 ); 152 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Pending Cancellation');147 update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Pending Cancellation' ); 153 148 } 154 149 … … 158 153 * @param Int $subscription_id Subscription ID. 159 154 */ 160 private static function user($subscription_id) 161 { 162 $user = new \WP_User(get_current_user_id()); 163 if (!empty($user->roles) && is_array($user->roles) && in_array('administrator', $user->roles, true)) { 155 private static function user( $subscription_id ) { 156 $user = new \WP_User( get_current_user_id() ); 157 if ( ! empty( $user->roles ) && is_array( $user->roles ) && in_array( 'administrator', $user->roles, true ) ) { 164 158 return; 165 159 } 166 160 167 if ( Helper::subscription_exists($subscription_id, 'active')) {168 $user->set_role( get_option('subscrpt_active_role', 'subscriber'));169 } elseif ( Helper::subscription_exists($subscription_id, array('cancelled', 'expired'))) {170 $user->set_role( get_option('subscrpt_unactive_role', 'customer'));161 if ( Helper::subscription_exists( $subscription_id, 'active' ) ) { 162 $user->set_role( get_option( 'subscrpt_active_role', 'subscriber' ) ); 163 } elseif ( Helper::subscription_exists( $subscription_id, array( 'cancelled', 'expired' ) ) ) { 164 $user->set_role( get_option( 'subscrpt_unactive_role', 'customer' ) ); 171 165 } 172 166 } -
subscription/trunk/includes/Illuminate/Cron.php
r2927437 r3083564 8 8 * @package SpringDevs\Subscription\Illuminate 9 9 */ 10 class Cron 11 { 10 class Cron { 12 11 13 12 /** 14 13 * Initialize the class. 15 14 */ 16 public function __construct() 17 { 18 add_action('subscrpt_daily_cron', array($this, 'daily_cron_task')); 15 public function __construct() { 16 add_action( 'subscrpt_daily_cron', array( $this, 'daily_cron_task' ) ); 19 17 } 20 18 … … 22 20 * Run daily cron task to check if subscription expired. 23 21 */ 24 public function daily_cron_task() 25 { 22 public function daily_cron_task() { 26 23 $args = array( 27 24 'post_type' => 'subscrpt_order', 28 'post_status' => array( 'active', 'pe_cancelled'),25 'post_status' => array( 'active', 'pe_cancelled' ), 29 26 'fields' => 'ids', 30 27 'author' => get_current_user_id(), 31 28 ); 32 29 33 $active_subscriptions = get_posts( $args);30 $active_subscriptions = get_posts( $args ); 34 31 35 if ( $active_subscriptions && count($active_subscriptions) > 0) {36 foreach ( $active_subscriptions as $subscription) {37 $post_meta = get_post_meta( $subscription, '_order_subscrpt_meta', true);32 if ( $active_subscriptions && count( $active_subscriptions ) > 0 ) { 33 foreach ( $active_subscriptions as $subscription ) { 34 $post_meta = get_post_meta( $subscription, '_order_subscrpt_meta', true ); 38 35 39 if ( time() >= $post_meta['next_date'] || (null !== $post_meta['trial'] && time() >= $post_meta['start_date'])) {40 if ( 'pe_cancelled' === get_post_status($subscription)) {41 Action::status( 'cancelled', $subscription);36 if ( time() >= $post_meta['next_date'] || ( null !== $post_meta['trial'] && time() >= $post_meta['start_date'] ) ) { 37 if ( 'pe_cancelled' === get_post_status( $subscription ) ) { 38 Action::status( 'cancelled', $subscription ); 42 39 } else { 43 Action::status( 'expired', $subscription);40 Action::status( 'expired', $subscription ); 44 41 } 45 42 } -
subscription/trunk/includes/Illuminate/Helper.php
r2927437 r3083564 67 67 */ 68 68 public static function subscription_exists( int $product_id, $status ) { 69 if ( 0 === get_current_user_id() ) { 70 return false; 71 } 72 69 73 $args = array( 70 74 'post_type' => 'subscrpt_order', … … 204 208 } 205 209 206 /**207 * Get total subscriptions by product ID.208 *209 * @param Int $product_id Product ID.210 * @param String | array $status Status.211 *212 * @return \WP_Post | false213 */210 /** 211 * Get total subscriptions by product ID. 212 * 213 * @param Int $product_id Product ID. 214 * @param String | array $status Status. 215 * 216 * @return \WP_Post | false 217 */ 214 218 public static function get_total_subscriptions_from_product( int $product_id, $status = array( 'active', 'pending', 'expired', 'pe_cancelled', 'cancelled' ) ) { 215 219 $args = array( -
subscription/trunk/includes/Illuminate/Order.php
r2927437 r3083564 19 19 add_action( 'woocommerce_before_order_itemmeta', array( $this, 'add_order_item_data' ), 10, 3 ); 20 20 add_action( 'woocommerce_order_status_changed', array( $this, 'order_status_changed' ) ); 21 add_action( 'woocommerce_before_delete_order', array( $this, 'delete_the_subscription' ) ); 21 22 } 22 23 … … 123 124 } 124 125 } 126 127 /** 128 * Delete the subscription. 129 * 130 * @param int $order_id Order ID. 131 * 132 * @return void 133 */ 134 public function delete_the_subscription( $order_id ) { 135 global $wpdb; 136 $table_name = $wpdb->prefix . 'subscrpt_order_relation'; 137 138 $histories = Helper::get_subscriptions_from_order( $order_id ); 139 foreach ( (array) $histories as $history ) { 140 $subscription_meta = get_post_meta( $history->subscription_id, '_order_subscrpt_meta', true ); 141 if ( (int) $subscription_meta['order_id'] === $order_id ) { 142 wp_delete_post( $history->subscription_id, true ); 143 } 144 } 145 146 // phpcs:ignore 147 $wpdb->delete( $table_name, array( 'order_id' => $order_id ), array( '%d' ) ); 148 } 125 149 } -
subscription/trunk/includes/Illuminate/Post.php
r2927437 r3083564 36 36 'view_items' => __( 'View Subscription', 'sdevs_subscrpt' ), 37 37 'search_items' => __( 'Search Subscription', 'sdevs_subscrpt' ), 38 'not_found' => __( 'No subscriptions found.', 'sdevs_subscrpt' ), 38 39 ); 39 40 -
subscription/trunk/includes/functions.php
r2927437 r3083564 1 1 <?php 2 3 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; 2 4 3 5 /** … … 10 12 * @return String 11 13 */ 12 function subscrpt_get_action_url($action, $nonce, $subscription_id) 13 { 14 function subscrpt_get_action_url( $action, $nonce, $subscription_id ) { 14 15 return add_query_arg( 15 16 array( … … 18 19 'wpnonce' => $nonce, 19 20 ), 20 wc_get_endpoint_url( 'view-subscription', $subscription_id, wc_get_page_permalink('myaccount'))21 wc_get_endpoint_url( 'view-subscription', $subscription_id, wc_get_page_permalink( 'myaccount' ) ) 21 22 ); 22 23 } 23 24 24 25 25 function subscrpt_get_typos($number, $typo) 26 { 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'); 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 35 } else { 36 36 return $typo; … … 46 46 * @return string 47 47 */ 48 function subscrpt_next_date($time, $trial = null) 49 { 50 if (null === $trial) { 48 function subscrpt_next_date( $time, $trial = null ) { 49 if ( null === $trial ) { 51 50 $start_date = time(); 52 51 } else { 53 $start_date = strtotime( $trial);52 $start_date = strtotime( $trial ); 54 53 } 55 54 56 return gmdate( 'F d, Y', strtotime($time, $start_date));55 return gmdate( 'F d, Y', strtotime( $time, $start_date ) ); 57 56 } 58 57 … … 62 61 * @return bool 63 62 */ 64 function subscrpt_pro_activated(): bool 65 { 66 return class_exists('Sdevs_Wc_Subscription_Pro'); 63 function subscrpt_pro_activated(): bool { 64 return class_exists( 'Sdevs_Wc_Subscription_Pro' ); 67 65 } 68 66 … … 72 70 * @return string 73 71 */ 74 function subscrpt_get_renewal_process() 75 { 76 if (!subscrpt_pro_activated()) { 72 function subscrpt_get_renewal_process() { 73 if ( ! subscrpt_pro_activated() ) { 77 74 return 'manual'; 78 75 } else { 79 return get_option( 'subscrpt_renewal_process', 'auto');76 return get_option( 'subscrpt_renewal_process', 'auto' ); 80 77 } 81 78 } … … 88 85 * @return string 89 86 */ 90 function order_relation_type_cast(string $key) 91 { 87 function order_relation_type_cast( string $key ) { 92 88 $relational_type_keys = apply_filters( 93 89 'subscrpt_order_relational_types', 94 90 array( 95 'new' => __( 'New Subscription Order', 'sdevs_subscrpt'),96 'renew' => __( 'Renewal Order', 'sdevs_subscrpt'),91 'new' => __( 'New Subscription Order', 'sdevs_subscrpt' ), 92 'renew' => __( 'Renewal Order', 'sdevs_subscrpt' ), 97 93 ) 98 94 ); 99 95 100 return $relational_type_keys[ $key];96 return $relational_type_keys[ $key ]; 101 97 } 98 99 if ( ! function_exists( 'is_wc_order_hpos_enabled' ) ) { 100 /** 101 * Check if HPOS enabled. 102 */ 103 function is_wc_order_hpos_enabled() { 104 return function_exists( 'wc_get_container' ) ? 105 wc_get_container() 106 ->get( CustomOrdersTableController::class ) 107 ->custom_orders_table_usage_is_enabled() 108 : false; 109 } 110 } 111 112 if ( ! function_exists( 'sdevs_wp_strtotime' ) ) { 113 /** 114 * Get strtotime with WordPress timezone config. 115 * 116 * @param string $str string. 117 * @param int|null $base_timestamp base timestamp. 118 * 119 * @return int 120 */ 121 function sdevs_wp_strtotime( $str, $base_timestamp = null ) { 122 return strtotime( wp_date( 'Y-m-d H:i:s', strtotime( $str, $base_timestamp ) ) ); 123 } 124 } -
subscription/trunk/readme.txt
r3070491 r3083564 5 5 Requires at least: 4.0 6 6 Tested up to: 6.5 7 Stable tag: 1.1. 17 Stable tag: 1.1.2 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 48 48 3. Activate the `WooCommerce Subscription` plugin. 49 49 50 == Frequently Asked Questions == 51 =Is this plugin compatible with WooCommerce block pages?= 52 No, This plugin isn't compatible with WooCommerce block pages. You need to continue with shortcode pages. 53 50 54 51 55 == Screenshots == … … 66 70 67 71 == Changelog == 72 73 = 1.1.2 = 74 - **Fix:** Handle order deletion. 75 - **Update:** WP timezone setting support added. 76 - **New:** Compatible with pro version. 68 77 69 78 = 1.1.1 = -
subscription/trunk/subscription.php
r3070491 r3083564 4 4 Plugin URI: https://wordpress.org/plugins/subscription 5 5 Description: Allow your customers to order once and get their products and services every month/week. 6 Version: 1.1. 16 Version: 1.1.2 7 7 Author: SpringDevs 8 8 Author URI: https://springdevs.com/ 9 Requires Plugins: woocommerce 9 10 License: GPLv2 10 11 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 59 60 * @var string 60 61 */ 61 const version = '1.1. 1';62 const version = '1.1.2'; 62 63 63 64 /** -
subscription/trunk/templates/myaccount/single.php
r2927437 r3083564 4 4 * 5 5 * @var WC_Order $order 6 * @var WC_Order_Item $order_item 6 7 * @var array $post_meta 7 8 * @var stdClass $status … … 96 97 <?php 97 98 $product_name = $order_item->get_name(); 98 $product_link = get_permalink( $order_item->get_ product_id() );99 $product_link = get_permalink( $order_item->get_variation_id() !== 0 ? $order_item->get_variation_id() : $order_item->get_product_id() ); 99 100 $order_item_meta = $order_item->get_meta( '_subscrpt_meta', true ); 100 101 $time = '1' === $order_item_meta['time'] ? null : $order_item_meta['time']; -
subscription/trunk/vendor/composer/installed.php
r3070491 r3083564 4 4 'pretty_version' => 'dev-next', 5 5 'version' => 'dev-next', 6 'reference' => ' 4a0f37433e657ead368a73fcc1a5cac48231b997',6 'reference' => 'a6c55e7f6e77bfec3168a81d3148adbb4d9cff40', 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-next', 15 15 'version' => 'dev-next', 16 'reference' => ' 4a0f37433e657ead368a73fcc1a5cac48231b997',16 'reference' => 'a6c55e7f6e77bfec3168a81d3148adbb4d9cff40', 17 17 'type' => 'wordpress-plugin', 18 18 'install_path' => __DIR__ . '/../../',
Note: See TracChangeset
for help on using the changeset viewer.