Plugin Directory

Changeset 3083564


Ignore:
Timestamp:
05/08/2024 09:00:08 PM (22 months ago)
Author:
ok9xnirab
Message:

v1.1.2 released.

Location:
subscription/trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • subscription/trunk/includes/Admin/Order.php

    r2927437 r3083564  
    2323     */
    2424    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();
    2629        $histories = Helper::get_subscriptions_from_order( $order_id );
    2730        if ( is_array( $histories ) ) {
     
    3134                __( 'Related Subscriptions', 'sdevs_subscrpt' ),
    3235                array( $this, 'subscrpt_order_related' ),
    33                 'shop_order',
     36                $screen,
    3437                'normal',
    3538                'default',
  • subscription/trunk/includes/Admin/Subscriptions.php

    r2927437 r3083564  
    219219    }
    220220
     221    /**
     222     * Display subscription info.
     223     *
     224     * @return void
     225     */
    221226    public function subscrpt_order_info() {
    222227        $post_meta = get_post_meta( get_the_ID(), '_order_subscrpt_meta', true );
     
    282287
    283288        $post_meta = get_post_meta( $post_id, '_order_subscrpt_meta', true );
    284         if ( $action === 'active' ) {
     289        if ( 'active' === $action ) {
    285290            $order = wc_get_order( $post_meta['order_id'] );
    286291            $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        }
    290296    }
    291297}
  • subscription/trunk/includes/Admin/views/order-history.php

    r2927437 r3083564  
    2020            ?>
    2121            <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>
    2323                <td><?php echo wp_kses_post( order_relation_type_cast( $order_history->type ) ); ?></td>
    2424                <td>
  • subscription/trunk/includes/Admin/views/subscription-customer.php

    r2797349 r3083564  
    2020            <tr class="view">
    2121                <th>&nbsp;</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>
    2323            </tr>
    2424        </tbody>
  • subscription/trunk/includes/Admin/views/subscription-order-info.php

    r2927437 r3083564  
    4848            <td><?php echo esc_html( $order->get_payment_method_title() ); ?></td>
    4949        </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; ?>
    5061        <tr>
    5162            <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>
    5364        </tr>
    5465        <tr>
  • subscription/trunk/includes/Frontend/Checkout.php

    r2927437 r3083564  
    1616    public function __construct() {
    1717        add_action( 'woocommerce_checkout_order_processed', array( $this, 'create_subscription_after_checkout' ) );
     18        add_action( 'woocommerce_resume_order', array( $this, 'remove_subscriptions' ) );
    1819    }
    1920
     
    6364                    if ( ! empty( $post_meta['trial_time'] ) && $post_meta['trial_time'] > 0 && ! $is_renew && $has_trial ) {
    6465                        $trial      = $post_meta['trial_time'] . ' ' . Helper::get_typos( $post_meta['trial_time'], $post_meta['trial_type'] );
    65                         $start_date = strtotime( $trial );
     66                        $start_date = sdevs_wp_strtotime( $trial );
    6667                    }
    67 
    6868                    $order_item_meta = array(
    6969                        'order_id'      => $order_id,
     
    7171                        'trial'         => $trial,
    7272                        'start_date'    => $start_date,
    73                         'next_date'     => strtotime( $post_meta['time'] . ' ' . $type, $start_date ),
     73                        'next_date'     => sdevs_wp_strtotime( $post_meta['time'] . ' ' . $type, $start_date ),
    7474                    );
    7575
     
    8888                    // Renew subscription if need!
    8989                    $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 ) {
    9191                        $comment_id = wp_insert_comment(
    9292                            array(
    9393                                '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                                ),
    9599                                'comment_post_ID' => $renew_subscription_id,
    96100                                'comment_type'    => 'order_note',
     
    154158        }
    155159    }
     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    }
    156188}
  • subscription/trunk/includes/Frontend/MyAccount.php

    r2927437 r3083564  
    88 * @package SpringDevs\Subscription\Frontend
    99 */
    10 class MyAccount
    11 {
     10class MyAccount {
     11
    1212
    1313    /**
    1414     * Initialize the class
    1515     */
    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' ) );
    2625    }
    2726
     
    3332     * @return array
    3433     */
    35     public function custom_query_vars(array $query_vars): array
    36     {
     34    public function custom_query_vars( array $query_vars ): array {
    3735        $query_vars['view-subscription'] = 'view-subscription';
    3836        return $query_vars;
     
    4442     * @param Int $id Post ID.
    4543     */
    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 );
    5350
    54         $subscrpt_nonce = wp_create_nonce('subscrpt_nonce');
     51        $subscrpt_nonce = wp_create_nonce( 'subscrpt_nonce' );
    5552        $action_buttons = array();
    5653
    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 ) {
    5956                $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' ),
    6259                    'class' => 'cancel',
    6360                );
    64             } elseif (trim($status) === trim('pe_cancelled')) {
     61            } elseif ( trim( $status ) === trim( 'pe_cancelled' ) ) {
    6562                $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' ),
    6865                );
    69             } elseif ('expired' === $status && 'pending' !== $order->get_status()) {
     66            } elseif ( 'expired' === $status && 'pending' !== $order->get_status() ) {
    7067                $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' ),
    7370                );
    7471            }
    7572
    76             if ('pending' === $order->get_status()) {
     73            if ( 'pending' === $order->get_status() ) {
    7774                $action_buttons['pay_now'] = array(
    7875                    'url'   => $order->get_checkout_payment_url(),
    79                     'label' => __('Pay now', 'sdevs_subscrpt'),
     76                    'label' => __( 'Pay now', 'sdevs_subscrpt' ),
    8077                );
    8178            }
    8279        }
    8380
    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 );
    8683
    8784        wc_get_template(
     
    9592                'user_cancel'     => $user_cancel,
    9693                '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' ) : '',
    9895            ),
    9996            'subscription',
     
    105102     * Re-write flush
    106103     */
    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 );
    110106        flush_rewrite_rules();
    111107    }
     
    118114     * @return String
    119115     */
    120     public function change_single_title(string $title): string
    121     {
     116    public function change_single_title( string $title ): string {
    122117        /* 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' ) );
    124119    }
    125120
     
    131126     * @return String
    132127     */
    133     public function change_lists_title(string $title): string
    134     {
     128    public function change_lists_title( string $title ): string {
    135129        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' );
    139133        }
    140134        return $title;
     
    147141     * @return array
    148142     */
    149     public function custom_my_account_menu_items(array $items): array
    150     {
     143    public function custom_my_account_menu_items( array $items ): array {
    151144        $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' );
    154147        $items['customer-logout'] = $logout;
    155148        return $items;
     
    159152     * Subscription Single EndPoint Content
    160153     */
    161     public function subscrpt_endpoint_content()
    162     {
     154    public function subscrpt_endpoint_content() {
    163155        wc_get_template(
    164156            'myaccount/subscriptions.php',
    165157            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' ) : '',
    167159            ),
    168160            'subscription',
     
    174166     * Enqueue assets
    175167     */
    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' );
    179170    }
    180171}
  • subscription/trunk/includes/Frontend/Product.php

    r3070491 r3083564  
    242242                }
    243243            }
    244             $price_html = $price . '/' . $time . $type . $signup_fee_html . $trial;
     244            $price_html = $price . ' / ' . $time . $type . $signup_fee_html . $trial;
    245245            return $price_html;
    246246        else :
  • subscription/trunk/includes/Illuminate/Action.php

    r2927437 r3083564  
    88 * @package SpringDevs\Subscription\Illuminate
    99 */
    10 class Action
    11 {
     10class Action {
     11
    1212
    1313    /**
     
    1616     * @param string $status Status.
    1717     * @param Int    $subscription_id Subscription ID.
     18     * @param bool   $write_comment Write comment?.
    1819     */
    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 ) {
    2221        wp_update_post(
    2322            array(
     
    2726        );
    2827
    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 );
    3233    }
    3334
     
    3839     * @param Int    $subscription_id Subscription ID.
    3940     */
    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 ) {
    4343            case 'expired':
    44                 self::expired($subscription_id);
     44                self::expired( $subscription_id );
    4545                break;
    4646            case 'active':
    47                 self::active($subscription_id);
     47                self::active( $subscription_id );
    4848                break;
    4949            case 'pending':
    50                 self::pending($subscription_id);
     50                self::pending( $subscription_id );
    5151                break;
    5252            case 'cancelled':
    53                 self::cancelled($subscription_id);
     53                self::cancelled( $subscription_id );
    5454                break;
    5555            case 'pe_cancelled':
    56                 self::pe_cancelled($subscription_id);
     56                self::pe_cancelled( $subscription_id );
    5757                break;
    5858        }
     
    6464     * @param int $subscription_id Subscription ID.
    6565     */
    66     private static function expired(int $subscription_id)
    67     {
     66    private static function expired( int $subscription_id ) {
    6867        $comment_id = wp_insert_comment(
    6968            array(
     
    7473            )
    7574        );
    76         update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Expired');
     75        update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Expired' );
    7776
    78         do_action('subscrpt_subscription_expired', $subscription_id);
     77        do_action( 'subscrpt_subscription_expired', $subscription_id );
    7978    }
    8079
     
    8483     * @param int $subscription_id Subscription ID.
    8584     */
    86     private static function active(int $subscription_id)
    87     {
     85    private static function active( int $subscription_id ) {
    8886        $comment_id = wp_insert_comment(
    8987            array(
     
    9492            )
    9593        );
    96         update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Activated');
     94        update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Activated' );
    9795
    98         do_action('subscrpt_subscription_activated', $subscription_id);
     96        do_action( 'subscrpt_subscription_activated', $subscription_id );
    9997    }
    10098
     
    104102     * @param int $subscription_id Subscription ID.
    105103     */
    106     private static function pending(int $subscription_id)
    107     {
     104    private static function pending( int $subscription_id ) {
    108105        $comment_id = wp_insert_comment(
    109106            array(
     
    114111            )
    115112        );
    116         update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Pending');
     113        update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Pending' );
    117114    }
    118115
     
    122119     * @param int $subscription_id Subscription ID.
    123120     */
    124     private static function cancelled(int $subscription_id)
    125     {
     121    private static function cancelled( int $subscription_id ) {
    126122        $comment_id = wp_insert_comment(
    127123            array(
     
    132128            )
    133129        );
    134         update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Cancelled');
     130        update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Cancelled' );
    135131    }
    136132
     
    140136     * @param int $subscription_id Subscription ID.
    141137     */
    142     private static function pe_cancelled(int $subscription_id)
    143     {
     138    private static function pe_cancelled( int $subscription_id ) {
    144139        $comment_id = wp_insert_comment(
    145140            array(
     
    150145            )
    151146        );
    152         update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Pending Cancellation');
     147        update_comment_meta( $comment_id, '_subscrpt_activity', 'Subscription Pending Cancellation' );
    153148    }
    154149
     
    158153     * @param Int $subscription_id Subscription ID.
    159154     */
    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 ) ) {
    164158            return;
    165159        }
    166160
    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' ) );
    171165        }
    172166    }
  • subscription/trunk/includes/Illuminate/Cron.php

    r2927437 r3083564  
    88 * @package SpringDevs\Subscription\Illuminate
    99 */
    10 class Cron
    11 {
     10class Cron {
    1211
    1312    /**
    1413     * Initialize the class.
    1514     */
    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' ) );
    1917    }
    2018
     
    2220     * Run daily cron task to check if subscription expired.
    2321     */
    24     public function daily_cron_task()
    25     {
     22    public function daily_cron_task() {
    2623        $args = array(
    2724            'post_type'   => 'subscrpt_order',
    28             'post_status' => array('active', 'pe_cancelled'),
     25            'post_status' => array( 'active', 'pe_cancelled' ),
    2926            'fields'      => 'ids',
    3027            'author'      => get_current_user_id(),
    3128        );
    3229
    33         $active_subscriptions = get_posts($args);
     30        $active_subscriptions = get_posts( $args );
    3431
    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 );
    3835
    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 );
    4239                    } else {
    43                         Action::status('expired', $subscription);
     40                        Action::status( 'expired', $subscription );
    4441                    }
    4542                }
  • subscription/trunk/includes/Illuminate/Helper.php

    r2927437 r3083564  
    6767     */
    6868    public static function subscription_exists( int $product_id, $status ) {
     69        if ( 0 === get_current_user_id() ) {
     70            return false;
     71        }
     72
    6973        $args = array(
    7074            'post_type'   => 'subscrpt_order',
     
    204208    }
    205209
    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 | false
    213         */
     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    */
    214218    public static function get_total_subscriptions_from_product( int $product_id, $status = array( 'active', 'pending', 'expired', 'pe_cancelled', 'cancelled' ) ) {
    215219        $args = array(
  • subscription/trunk/includes/Illuminate/Order.php

    r2927437 r3083564  
    1919        add_action( 'woocommerce_before_order_itemmeta', array( $this, 'add_order_item_data' ), 10, 3 );
    2020        add_action( 'woocommerce_order_status_changed', array( $this, 'order_status_changed' ) );
     21        add_action( 'woocommerce_before_delete_order', array( $this, 'delete_the_subscription' ) );
    2122    }
    2223
     
    123124        }
    124125    }
     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    }
    125149}
  • subscription/trunk/includes/Illuminate/Post.php

    r2927437 r3083564  
    3636            'view_items'        => __( 'View Subscription', 'sdevs_subscrpt' ),
    3737            'search_items'      => __( 'Search Subscription', 'sdevs_subscrpt' ),
     38            'not_found'         => __( 'No subscriptions found.', 'sdevs_subscrpt' ),
    3839        );
    3940
  • subscription/trunk/includes/functions.php

    r2927437 r3083564  
    11<?php
     2
     3use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
    24
    35/**
     
    1012 * @return String
    1113 */
    12 function subscrpt_get_action_url($action, $nonce, $subscription_id)
    13 {
     14function subscrpt_get_action_url( $action, $nonce, $subscription_id ) {
    1415    return add_query_arg(
    1516        array(
     
    1819            'wpnonce'     => $nonce,
    1920        ),
    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' ) )
    2122    );
    2223}
    2324
    2425
    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');
     26function 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' );
    3535    } else {
    3636        return $typo;
     
    4646 * @return string
    4747 */
    48 function subscrpt_next_date($time, $trial = null)
    49 {
    50     if (null === $trial) {
     48function subscrpt_next_date( $time, $trial = null ) {
     49    if ( null === $trial ) {
    5150        $start_date = time();
    5251    } else {
    53         $start_date = strtotime($trial);
     52        $start_date = strtotime( $trial );
    5453    }
    5554
    56     return gmdate('F d, Y', strtotime($time, $start_date));
     55    return gmdate( 'F d, Y', strtotime( $time, $start_date ) );
    5756}
    5857
     
    6261 * @return bool
    6362 */
    64 function subscrpt_pro_activated(): bool
    65 {
    66     return class_exists('Sdevs_Wc_Subscription_Pro');
     63function subscrpt_pro_activated(): bool {
     64    return class_exists( 'Sdevs_Wc_Subscription_Pro' );
    6765}
    6866
     
    7270 * @return string
    7371 */
    74 function subscrpt_get_renewal_process()
    75 {
    76     if (!subscrpt_pro_activated()) {
     72function subscrpt_get_renewal_process() {
     73    if ( ! subscrpt_pro_activated() ) {
    7774        return 'manual';
    7875    } else {
    79         return get_option('subscrpt_renewal_process', 'auto');
     76        return get_option( 'subscrpt_renewal_process', 'auto' );
    8077    }
    8178}
     
    8885 * @return string
    8986 */
    90 function order_relation_type_cast(string $key)
    91 {
     87function order_relation_type_cast( string $key ) {
    9288    $relational_type_keys = apply_filters(
    9389        'subscrpt_order_relational_types',
    9490        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' ),
    9793        )
    9894    );
    9995
    100     return $relational_type_keys[$key];
     96    return $relational_type_keys[ $key ];
    10197}
     98
     99if ( ! 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
     112if ( ! 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  
    55Requires at least: 4.0
    66Tested up to: 6.5
    7 Stable tag: 1.1.1
     7Stable tag: 1.1.2
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    4848        3. Activate the `WooCommerce Subscription` plugin.
    4949
     50== Frequently Asked Questions ==
     51=Is this plugin compatible with WooCommerce block pages?=
     52No, This plugin isn't compatible with WooCommerce block pages. You need to continue with shortcode pages.
     53
    5054
    5155== Screenshots ==
     
    6670
    6771== Changelog ==
     72
     73= 1.1.2 =
     74- **Fix:** Handle order deletion.
     75- **Update:** WP timezone setting support added.
     76- **New:** Compatible with pro version.
    6877
    6978= 1.1.1 =
  • subscription/trunk/subscription.php

    r3070491 r3083564  
    44Plugin URI: https://wordpress.org/plugins/subscription
    55Description: Allow your customers to order once and get their products and services every month/week.
    6 Version: 1.1.1
     6Version: 1.1.2
    77Author: SpringDevs
    88Author URI: https://springdevs.com/
     9Requires Plugins: woocommerce
    910License: GPLv2
    1011License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    5960     * @var string
    6061     */
    61     const version = '1.1.1';
     62    const version = '1.1.2';
    6263
    6364    /**
  • subscription/trunk/templates/myaccount/single.php

    r2927437 r3083564  
    44 *
    55 * @var WC_Order $order
     6 * @var WC_Order_Item $order_item
    67 * @var array $post_meta
    78 * @var stdClass $status
     
    9697        <?php
    9798        $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() );
    99100        $order_item_meta    = $order_item->get_meta( '_subscrpt_meta', true );
    100101        $time               = '1' === $order_item_meta['time'] ? null : $order_item_meta['time'];
  • subscription/trunk/vendor/composer/installed.php

    r3070491 r3083564  
    44        'pretty_version' => 'dev-next',
    55        'version' => 'dev-next',
    6         'reference' => '4a0f37433e657ead368a73fcc1a5cac48231b997',
     6        'reference' => 'a6c55e7f6e77bfec3168a81d3148adbb4d9cff40',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-next',
    1515            'version' => 'dev-next',
    16             'reference' => '4a0f37433e657ead368a73fcc1a5cac48231b997',
     16            'reference' => 'a6c55e7f6e77bfec3168a81d3148adbb4d9cff40',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.