Plugin Directory

Changeset 2984097


Ignore:
Timestamp:
10/26/2023 01:19:56 AM (2 years ago)
Author:
thanhtd
Message:

Update

Location:
subre-product-subscription-for-woo/trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • subre-product-subscription-for-woo/trunk/CHANGELOG.txt

    r2861966 r2984097  
     1/**1.0.2 - 2023.10.26**/
     2– Updated: Compatible with WordPress 6.3 & WooCommerce 8.2
     3
     4/**1.0.1 - 2023.07.03**/
     5– Updated: Compatible with WooCommerce HPOS(COT)
     6
    17/**1.0.0 - 2023.02.08**/
    28~ The first released
  • subre-product-subscription-for-woo/trunk/admin/admin.php

    r2861966 r2984097  
    4141                    'slug'       => 'subre-product-subscription-for-woo',
    4242                    'menu_slug'  => 'subre-product-subscription-for-woo',
    43                     'survey_url' => '',
     43                    'survey_url' => 'https://script.google.com/macros/s/AKfycbzFUSL8LQlMK65VltDG1a-JVESk8IlYQSSgAvhSJLWH47obp8NA3MDUSgSS8z9iIwNgXA/exec',
    4444                    'version'    => SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_VERSION
    4545                )
  • subre-product-subscription-for-woo/trunk/frontend/cart.php

    r2865411 r2984097  
    1414        add_filter( 'woocommerce_cart_item_price', array( $this, 'change_subscription_price_html_in_cart' ), 10, 3 );
    1515        add_filter( 'woocommerce_order_button_text', array( $this, 'change_order_button_text' ) );
    16         add_filter( 'woocommerce_cart_item_subtotal', array(
    17             $this,
    18             'change_subscription_subtotal_html_in_cart'
    19         ), 10, 3 );
     16        add_filter( 'woocommerce_cart_item_subtotal', array( $this, 'change_subscription_subtotal_html_in_cart' ), 10, 3 );
    2017        /*Change subscription price while calculating total*/
    2118        add_action( 'woocommerce_before_calculate_totals', array( $this, 'add_calculation_price_filter' ) );
    2219        add_action( 'woocommerce_calculate_totals', array( $this, 'remove_calculation_price_filter' ) );
    2320        add_action( 'woocommerce_after_calculate_totals', array( $this, 'remove_calculation_price_filter' ) );
     21        add_action( 'woocommerce_cart_calculate_fees', [ $this, 'add_signup_fee' ] );
    2422    }
    2523
     
    7371     *
    7472     * @return array|mixed|string
     73     * @throws Exception
    7574     */
    7675    public function change_subscription_price_html_in_cart( $price, $cart_item, $cart_item_key ) {
     
    122121        return $contains_subscription;
    123122    }
     123
     124    /**
     125     * @param $cart \WC_Cart
     126     */
     127    public function add_signup_fee( $cart ) {
     128        $cart_contents = $cart->get_cart_contents();
     129        $signup_fees   = 0;
     130
     131        if ( ! empty( $cart_contents ) ) {
     132            $settings = SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_instance();
     133            foreach ( $cart_contents as $item ) {
     134
     135                if ( SUBRE_SUBSCRIPTION_PRODUCT_HELPER::is_subscription( $item['product_id'] ) ) {
     136                    $product = wc_get_product( $item['product_id'] );
     137                    if ( $product ) {
     138                        $signup_fee = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_product_sign_up_fee( $product );
     139                        $trial      = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_subscription_trial_period( $product );
     140
     141                        if ( ! $trial || ( $trial && $settings->get_params( 'sign_up_fee_if_trial' ) ) ) {
     142                            $signup_fees += $signup_fee * $item['quantity'];
     143                        }
     144                    }
     145                }
     146            }
     147        }
     148
     149        if ( $signup_fees > 0 ) {
     150            $cart->add_fee( __( 'Sign up fee', 'subre-product-subscription-for-woo' ), $signup_fees, true, '' );
     151        }
     152    }
    124153}
  • subre-product-subscription-for-woo/trunk/frontend/checkout.php

    r2865411 r2984097  
    8181            $args      = array(
    8282                'post_type'      => 'subre_subscription',
    83                 'post_status'    => array(
    84                     'wc-pending',
    85                     'wc-on-hold',
    86                 ),
     83                'post_status'    => array( 'wc-pending', 'wc-on-hold' ),
    8784                'posts_per_page' => - 1,
    8885                'post_parent'    => $order_id,
     
    124121     * @return float|int|string
    125122     */
    126     public static function get_subscription_price( $product, $is_recurring = false ) {
    127         if ( $is_recurring ) {
    128             $price = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_item_price( $product );
    129         } else {
    130             $instance    = SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_instance();
    131             $sign_up_fee = $product->get_meta( '_subre_product_sign_up_fee', true );
    132             if ( SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_subscription_trial_period( $product ) ) {
    133                 if ( $instance->get_params( 'sign_up_fee_if_trial' ) ) {
    134                     $price = $sign_up_fee;
    135                 } else {
    136                     $price = 0;
    137                 }
    138             } else {
    139                 $price = $sign_up_fee;
    140             }
    141         }
    142 
    143         return $price;
    144     }
     123//  public static function get_subscription_price( $product, $is_recurring = false ) {
     124//      if ( $is_recurring ) {
     125//          $price = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_item_price( $product );
     126//      } else {
     127//          $instance    = SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_instance();
     128//          $sign_up_fee = $product->get_meta( '_subre_product_sign_up_fee', true );
     129//          if ( SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_subscription_trial_period( $product ) ) {
     130//              if ( $instance->get_params( 'sign_up_fee_if_trial' ) ) {
     131//                  $price = $sign_up_fee;
     132//              } else {
     133//                  $price = 0;
     134//              }
     135//          } else {
     136//              $price = $sign_up_fee;
     137//          }
     138//      }
     139//
     140//      return $price;
     141//  }
    145142}
  • subre-product-subscription-for-woo/trunk/frontend/product.php

    r2861966 r2984097  
    6767     *
    6868     * @return mixed
     69     * @throws Exception
    6970     */
    7071    public static function maybe_change_price_html( $price, $product ) {
  • subre-product-subscription-for-woo/trunk/includes/define.php

    r2861966 r2984097  
    1919define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_IMAGES', SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_ASSETS . "images/" );
    2020require_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'functions.php';
    21 require_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'support.php';
    2221require_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'data.php';
    2322require_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'subscription-product-helper.php';
  • subre-product-subscription-for-woo/trunk/includes/payment/stripe.php

    r2865411 r2984097  
    1515        add_action( 'subre_renewal_order_payment_due', array( $this, 'handle_payment' ), 10, 2 );
    1616
    17         add_action( 'subre_renewal_order_payment_stripe_failed', array(
    18             $this,
    19             'process_failed_payment'
    20         ), 10, 2 );
    21         add_action( 'subre_subscription_parent_order_payment_complete', array(
    22             $this,
    23             'copy_payment_data_to_subscription'
    24         ), 10, 2 );
    25         add_action( 'subre_new_renewal_order_created', array(
    26             $this,
    27             'copy_payment_data'
    28         ), 10, 3 );
     17        add_action( 'subre_renewal_order_payment_stripe_failed', array( $this, 'process_failed_payment' ), 10, 2 );
     18        add_action( 'subre_subscription_parent_order_payment_complete', array( $this, 'copy_payment_data_to_subscription' ), 10, 2 );
     19        add_action( 'subre_new_renewal_order_created', array( $this, 'copy_payment_data' ), 10, 3 );
    2920    }
    3021
     
    125116
    126117    public static function get_supported_payment_methods() {
    127         return array(
    128             'stripe',
    129             'stripe_sepa'
    130         );
     118        return array( 'stripe', 'stripe_sepa' );
    131119    }
    132120
     
    135123     * @param bool $retry
    136124     * @param bool $previous_error
     125     *
     126     * @throws WC_Data_Exception
    137127     */
    138128    public function process_subscription_payment( $renewal_order, $retry = true, $previous_error = false ) {
    139         if ( class_exists( 'WC_Stripe_Order_Handler' ) && is_callable( array(
    140                 'WC_Stripe_Order_Handler',
    141                 'get_instance'
    142             ) ) ) {
     129        if ( class_exists( 'WC_Stripe_Order_Handler' ) && is_callable( array( 'WC_Stripe_Order_Handler', 'get_instance' ) ) ) {
    143130            $stripe_order_handler = WC_Stripe_Order_Handler::get_instance();
    144131            try {
     
    168155                 */
    169156                if ( is_object( $source_object ) && empty( $source_object->error ) && $stripe_order_handler->need_update_idempotency_key( $source_object, $previous_error ) ) {
    170                     add_filter( 'wc_stripe_idempotency_key', [
    171                         $stripe_order_handler,
    172                         'change_idempotency_key'
    173                     ], 10, 2 );
     157                    add_filter( 'wc_stripe_idempotency_key', [ $stripe_order_handler, 'change_idempotency_key' ], 10, 2 );
    174158                }
    175159
  • subre-product-subscription-for-woo/trunk/includes/payment/stripe_cc.php

    r2865411 r2984097  
    1414        add_filter( 'wc_stripe_should_save_payment_method', array( $this, 'should_save_payment_method' ), 10, 3 );
    1515        add_action( 'subre_renewal_order_payment_due', array( $this, 'handle_payment' ), 10, 2 );
    16         add_action( 'subre_renewal_order_payment_stripe_cc_failed', array(
    17             $this,
    18             'process_failed_payment'
    19         ), 10, 2 );
    20         add_action( 'subre_subscription_parent_order_payment_complete', array(
    21             $this,
    22             'copy_payment_data_to_subscription'
    23         ), 10, 2 );
    24         add_action( 'subre_new_renewal_order_created', array(
    25             $this,
    26             'copy_payment_data'
    27         ), 10, 3 );
     16        add_action( 'subre_renewal_order_payment_stripe_cc_failed', array( $this, 'process_failed_payment' ), 10, 2 );
     17        add_action( 'subre_subscription_parent_order_payment_complete', array( $this, 'copy_payment_data_to_subscription' ), 10, 2 );
     18        add_action( 'subre_new_renewal_order_created', array( $this, 'copy_payment_data' ), 10, 3 );
    2819    }
    2920
     
    141132
    142133    /**
    143      * @param $renewal_order WC_Order
     134     * @param WC_Order $renewal_order
     135     *
     136     * @throws \Stripe\Exception\ApiErrorException
    144137     */
    145138    public function process_subscription_payment( $renewal_order ) {
     
    149142            $gateway         = WC_Stripe_Gateway::load();
    150143            $payment_gateway->set_payment_method_token( $renewal_order->get_meta( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN ) );
    151             if ( 'stripe_googlepay' === $payment_method ) {
    152                 $payment_client         = WC_Stripe_Payment_Factory::load( 'payment_intent', $payment_gateway, $gateway );
    153                 $args                   = $payment_client->get_payment_intent_args( $renewal_order );
    154                 $args['confirm']        = true;
    155                 $args['payment_method'] = trim( $payment_gateway->get_order_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $renewal_order ) );
    156144
    157                 if ( ( $customer = $payment_gateway->get_order_meta_data( WC_Stripe_Constants::CUSTOMER_ID, $renewal_order ) ) ) {
    158                     $args['customer'] = $customer;
    159                 }
    160                 $result = $gateway->mode( $renewal_order )->paymentIntents->create( $args );
    161                 if ( is_wp_error( $result ) ) {
    162                     $renewal_order->update_status( 'failed' );
    163                     $renewal_order->add_order_note( sprintf( __( 'Recurring payment for order failed. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ) );
     145//          if ( 'stripe_googlepay' === $payment_method ) {
     146            $payment_client         = WC_Stripe_Payment_Factory::load( 'payment_intent', $payment_gateway, $gateway );
     147            $args                   = $payment_client->get_payment_intent_args( $renewal_order );
     148            $args['confirm']        = true;
     149            $args['payment_method'] = trim( $payment_gateway->get_order_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $renewal_order ) );
    164150
    165                     return;
    166                 }
    167                 $this->process_charge( $result->charges->data[0], $renewal_order );
    168             } else {
    169                 $payment_charge = WC_Stripe_Payment_Factory::load( 'charge', $payment_gateway, $gateway );
    170                 $result         = $payment_charge->process_payment( $renewal_order, $payment_gateway );
    171                 if ( $result->complete_payment ) {
    172                     $this->process_charge( $result->charge, $renewal_order );
    173                 }
     151            if ( ( $customer = $payment_gateway->get_order_meta_data( WC_Stripe_Constants::CUSTOMER_ID, $renewal_order ) ) ) {
     152                $args['customer'] = $customer;
    174153            }
     154            $result = $gateway->mode( $renewal_order )->paymentIntents->create( $args );
     155            if ( is_wp_error( $result ) ) {
     156                $renewal_order->update_status( 'failed' );
     157                $renewal_order->add_order_note( sprintf( __( 'Recurring payment for order failed. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ) );
     158
     159                return;
     160            }
     161            $this->process_charge( $result->charges->data[0], $renewal_order );
     162//          } else {
     163//              $payment_charge = WC_Stripe_Payment_Factory::load( 'charge', $payment_gateway, $gateway );
     164//              $result         = $payment_charge->process_payment( $renewal_order, $payment_gateway );
     165//              if ( isset( $result->complete_payment ) ) {
     166//                  $this->process_charge( $result->charge, $renewal_order );
     167//              }
     168//          }
    175169        } catch ( WC_Stripe_Exception $e ) {
    176170            do_action( 'subre_renewal_order_payment_stripe_cc_failed', $renewal_order, $e );
  • subre-product-subscription-for-woo/trunk/includes/subscription-email.php

    r2861966 r2984097  
    7878            return;
    7979        }
    80         if ( $email && is_a( $email, 'WC_Email' ) && in_array( $email->id, array(
    81                 'customer_processing_order',
    82                 'new_order'
    83             ), true ) ) {
     80        if ( $email && is_a( $email, 'WC_Email' ) && in_array( $email->id, [ 'customer_processing_order', 'new_order' ], true ) ) {
    8481            $args             = array(
    8582                'post_type'      => 'subre_subscription',
  • subre-product-subscription-for-woo/trunk/includes/subscription-order.php

    r2865411 r2984097  
    99    public function __construct() {
    1010        self::$settings = SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_instance();
    11         add_action( 'woocommerce_register_post_type', array( $this, 'register_post_type' ) );
    12         add_filter( 'wc_order_statuses', array( $this, 'wc_order_statuses' ) );
    13         add_filter( 'woocommerce_can_reduce_order_stock', array(
    14             $this,
    15             'do_not_reduce_stock_for_renewal_orders'
    16         ), 10, 2 );
    17         add_action( 'woocommerce_order_status_changed', array( $this, 'cancel_subscription' ), 10, 4 );
    18         add_action( 'subre_view_subscription', array( $this, 'subscription_details' ) );
    19         add_filter( 'woocommerce_order_is_download_permitted', array(
    20             $this,
    21             'woocommerce_order_is_download_permitted'
    22         ), 10, 2 );
     11        add_action( 'woocommerce_register_post_type', [ $this, 'register_post_type' ] );
     12        add_filter( 'wc_order_statuses', [ $this, 'wc_order_statuses' ] );
     13        add_filter( 'woocommerce_can_reduce_order_stock', [ $this, 'do_not_reduce_stock_for_renewal_orders' ], 10, 2 );
     14        add_action( 'woocommerce_order_status_changed', [ $this, 'cancel_subscription' ], 10, 4 );
     15        add_action( 'subre_view_subscription', [ $this, 'subscription_details' ] );
     16        add_filter( 'woocommerce_order_is_download_permitted', [ $this, 'woocommerce_order_is_download_permitted' ], 10, 2 );
    2317    }
    2418
     
    165159            return new WP_Error( 'subre_error_invalid_order', esc_html__( 'Not a valid WooCommerce order object', 'subre-product-subscription-for-woo' ) );
    166160        }
     161
    167162        if ( ! SUBRE_SUBSCRIPTION_PRODUCT_HELPER::is_subscription( $product_id ) ) {
    168163            return new WP_Error( 'subre_error_not_a_subcription_product', esc_html__( 'Not a subscription product', 'subre-product-subscription-for-woo' ) );
    169164        }
     165
    170166        $order_id = $order->get_id();
    171167        if ( self::subscription_exists_in_order( $order_id, $product_id ) ) {
    172168            return new WP_Error( 'subre_error_subscription_exists_in_order', esc_html__( 'A subscription from this product already exists in this order', 'subre-product-subscription-for-woo' ) );
    173169        }
     170
    174171        $order_items  = $order->get_items();
    175172        $line_item_id = '';
     173
    176174        foreach ( $order_items as $item_id => $order_item ) {
    177175            if ( $order_item->get_product_id() == $product_id ) {
     
    181179            }
    182180        }
     181
    183182        if ( ! isset( $product ) ) {
    184183            return new WP_Error( 'subre_error_product_not_existing_in_order', esc_html__( 'Product not existing in order', 'subre-product-subscription-for-woo' ) );
    185184        }
     185
    186186        $date_created = $order->get_date_created();
    187187        $subscription = new WC_Order();
     
    192192            $subscription_ids = array();
    193193        }
     194
    194195        $sign_up_fee              = get_post_meta( $product_id, '_subre_product_sign_up_fee', true );
    195196        $subscription_period      = get_post_meta( $product_id, '_subre_product_period', true );
    196197        $subscription_period_unit = get_post_meta( $product_id, '_subre_product_period_unit', true );
     198
    197199        if ( $override_trial === false ) {
    198200            $trial_period = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_subscription_trial_period( $product );
     
    200202            $trial_period = $override_trial;
    201203        }
     204
    202205        $trial_period_unit  = get_post_meta( $product_id, '_subre_product_trial_period_unit', true );
    203206        $expire_after       = get_post_meta( $product_id, '_subre_product_expire_after', true );
     
    249252        $clone        = clone $product_line;
    250253        $clone->set_id( 0 );
     254
    251255        if ( $trial_period ) {
    252256            /*If trial, do not copy line product item total from order*/
     
    256260            $total = $product_line->get_total();
    257261        }
     262
    258263        $subscription->add_item( $clone );
    259264        $subscription->set_total( $total + $order->get_shipping_total() );
     
    273278            }
    274279        }
     280
    275281        self::copy_main_order_data( $subscription, $order );
    276282        self::copy_payment_method( $subscription, $order );
  • subre-product-subscription-for-woo/trunk/includes/subscription-product-helper.php

    r2865411 r2984097  
    5454        if ( self::is_subscription( $product ) ) {
    5555            $instance = SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_instance();
     56
    5657            if ( $for_shop ) {
    57                 remove_filter( 'woocommerce_get_price_html', array(
    58                     'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_Frontend_Product',
    59                     'maybe_change_price_html'
    60                 ) );
     58                remove_filter( 'woocommerce_get_price_html', array( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_Frontend_Product', 'maybe_change_price_html' ) );
    6159                $price = $product->get_price_html();
    62                 add_filter( 'woocommerce_get_price_html', array(
    63                     'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_Frontend_Product',
    64                     'maybe_change_price_html'
    65                 ), 10, 2 );
     60                add_filter( 'woocommerce_get_price_html', array( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_Frontend_Product', 'maybe_change_price_html' ), 10, 2 );
    6661            } else {
    67                 $price = self::get_item_price( $product, $quantity );
     62                if ( wc()->cart->display_prices_including_tax() ) {
     63                    $price = wc_get_price_including_tax( $product );
     64                } else {
     65                    $price = wc_get_price_excluding_tax( $product );
     66                }
     67//              $price = self::get_item_price( $product, $quantity );
    6868                $price = wc_price( $price );
    6969            }
     70
    7071            $sign_up_fee              = self::get_product_sign_up_fee( $product );
    7172            $subscription_period      = $product->get_meta( '_subre_product_period', true );
     
    7980                $price_html_with_trial_and_sign_up_fee = $instance->get_params( 'price_html_with_trial_and_sign_up_fee' );
    8081                if ( $price_html_with_trial_and_sign_up_fee ) {
    81                     $display = str_replace( array(
    82                         '{subscription_price}',
    83                         '{subscription_period}',
    84                         '{sign_up_fee}',
    85                         '{trial_period}'
    86                     ), array(
    87                         $price,
    88                         self::get_formatted_period( $subscription_period, $subscription_period_unit ),
    89                         wc_price( $quantity * $sign_up_fee ),
    90                         self::get_formatted_period( $trial_period, $trial_period_unit, true ),
    91                     ), $price_html_with_trial_and_sign_up_fee );
     82                    $display = str_replace(
     83                        array(
     84                            '{subscription_price}',
     85                            '{subscription_period}',
     86                            '{sign_up_fee}',
     87                            '{trial_period}'
     88                        ),
     89                        array(
     90                            $price,
     91                            self::get_formatted_period( $subscription_period, $subscription_period_unit ),
     92                            wc_price( $quantity * $sign_up_fee ),
     93                            self::get_formatted_period( $trial_period, $trial_period_unit, true ),
     94                        ),
     95                        $price_html_with_trial_and_sign_up_fee
     96                    );
    9297                }
    9398            } else {
     
    95100                    $price_html_with_trial = $instance->get_params( 'price_html_with_trial' );
    96101                    if ( $price_html_with_trial ) {
    97                         $display = str_replace( array(
    98                             '{subscription_price}',
    99                             '{subscription_period}',
    100                             '{trial_period}'
    101                         ), array(
    102                             $price,
    103                             self::get_formatted_period( $subscription_period, $subscription_period_unit ),
    104                             self::get_formatted_period( $trial_period, $trial_period_unit, true ),
    105                         ), $price_html_with_trial );
     102                        $display = str_replace(
     103                            array(
     104                                '{subscription_price}',
     105                                '{subscription_period}',
     106                                '{trial_period}'
     107                            ),
     108                            array(
     109                                $price,
     110                                self::get_formatted_period( $subscription_period, $subscription_period_unit ),
     111                                self::get_formatted_period( $trial_period, $trial_period_unit, true ),
     112                            ),
     113                            $price_html_with_trial
     114                        );
    106115                    }
    107116                } elseif ( $sign_up_fee ) {
    108117                    $price_html_with_sign_up_fee = $instance->get_params( 'price_html_with_sign_up_fee' );
    109118                    if ( $price_html_with_sign_up_fee ) {
    110                         $display = str_replace( array(
    111                             '{subscription_price}',
    112                             '{subscription_period}',
    113                             '{sign_up_fee}'
    114                         ), array(
    115                             $price,
    116                             self::get_formatted_period( $subscription_period, $subscription_period_unit ),
    117                             wc_price( $quantity * $sign_up_fee ),
    118                         ), $price_html_with_sign_up_fee );
     119                        $display = str_replace(
     120                            array(
     121                                '{subscription_price}',
     122                                '{subscription_period}',
     123                                '{sign_up_fee}'
     124                            ),
     125                            array(
     126                                $price,
     127                                self::get_formatted_period( $subscription_period, $subscription_period_unit ),
     128                                wc_price( $quantity * $sign_up_fee ),
     129                            ),
     130                            $price_html_with_sign_up_fee
     131                        );
    119132                    }
    120133                } else {
    121134                    $price_html = $instance->get_params( 'price_html' );
    122135                    if ( $price_html ) {
    123                         $display = str_replace( array(
    124                             '{subscription_price}',
    125                             '{subscription_period}',
    126                         ), array(
    127                             $price,
    128                             self::get_formatted_period( $subscription_period, $subscription_period_unit ),
    129                         ), $price_html );
    130                     }
    131                 }
    132             }
     136                        $display = str_replace(
     137                            array(
     138                                '{subscription_price}',
     139                                '{subscription_period}',
     140                            ),
     141                            array(
     142                                $price,
     143                                self::get_formatted_period( $subscription_period, $subscription_period_unit ),
     144                            ),
     145                            $price_html
     146                        );
     147                    }
     148                }
     149            }
     150
    133151            if ( $expire_after ) {
    134152                $expiry_date_info = $instance->get_params( 'expiry_date_info' );
     
    138156                        $expire_after_unit = $subscription_period_unit;
    139157                    }
     158
    140159                    switch ( $expire_after_unit ) {
    141160                        case 'year':
     
    153172                            break;
    154173                    }
     174
    155175                    $expiry_date = time() + $expire_after * self::get_unit_in_seconds( $expire_after_unit );
     176
    156177                    if ( $trial_period ) {
    157178                        $expiry_date += $trial_period * self::get_unit_in_seconds( $trial_period_unit );
    158179                    }
    159                     $display .= '<p>' . str_replace( array(
    160                             '{expiry_period}',
    161                             '{expiry_date}',
    162                         ), array(
    163                             $expire_period,
    164                             wc_format_datetime( SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_datetime( $expiry_date ) ),
    165                         ), $expiry_date_info ) . '</p>';
    166                 }
    167             }
    168         }
    169 
    170         return nl2br($display);
     180
     181                    $display .= '<p>' . str_replace(
     182                            array(
     183                                '{expiry_period}',
     184                                '{expiry_date}',
     185                            ),
     186                            array(
     187                                $expire_period,
     188                                wc_format_datetime( SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_datetime( $expiry_date ) ),
     189                            ),
     190                            $expiry_date_info ) . '</p>';
     191                }
     192            }
     193        }
     194
     195        return nl2br( $display );
    171196    }
    172197
     
    199224     */
    200225    public static function get_item_price( $item, $quantity = 1 ) {
    201         return wc_prices_include_tax() ? wc_get_price_including_tax(
    202             $item,
    203             array( 'qty' => $quantity ) ) : wc_get_price_excluding_tax(
    204             $item,
    205             array( 'qty' => $quantity ) );
     226        return wc_get_price_to_display( $item, array( 'qty' => $quantity ) );
    206227    }
    207228
     
    212233     */
    213234    public static function get_subscription_price( $product ) {
    214         $instance    = SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_instance();
    215         $sign_up_fee = self::get_product_sign_up_fee( $product );
    216         if ( self::get_subscription_trial_period( $product ) ) {
    217             if ( $instance->get_params( 'sign_up_fee_if_trial' ) ) {
    218                 $price = $sign_up_fee;
    219             } else {
    220                 $price = 0;
    221             }
    222         } else {
    223             $price = self::get_item_price( $product ) + $sign_up_fee;
    224         }
    225 
    226         return $price;
     235        return self::get_subscription_trial_period( $product ) ? 0 : self::get_item_price( $product );
    227236    }
    228237
     
    269278    public static function get_product_sign_up_fee( $product ) {
    270279        $sign_up_fee = $product->get_meta( '_subre_product_sign_up_fee', true );
     280        $sign_up_fee = wc_get_price_to_display( $product, [ 'price' => $sign_up_fee ] );
    271281        if ( $sign_up_fee ) {
    272282            $sign_up_fee = apply_filters( 'wmc_change_3rd_plugin_price', $sign_up_fee );
  • subre-product-subscription-for-woo/trunk/includes/subscription-schedule.php

    r2861966 r2984097  
    169169
    170170            $renewal_order = wc_get_order( $renewal_id );
     171
    171172            if ( $renewal_order ) {
    172173                if ( ! $renewal_order->is_paid() ) {
  • subre-product-subscription-for-woo/trunk/includes/support.php

    r2861966 r2984097  
    88    /**
    99     * Class VillaTheme_Support
    10      * 1.1.7
     10     * 1.1.8
    1111     */
    1212    class VillaTheme_Support {
    1313        protected $plugin_base_name;
    1414        protected $ads_data;
    15         protected $version = '1.1.7';
     15        protected $version = '1.1.8';
     16        protected $data = [];
    1617
    1718        public function __construct( $data ) {
     
    702703            $wp_admin_bar->add_node( array(
    703704                'id'     => 'villatheme_hide_toolbar',
    704                 'title'  => '<span style="font-family:dashicons" class="dashicons dashicons-dismiss"></span><span class="villatheme-hide-toolbar-button-title">Hide VillaTheme toolbar</span>',
     705                'title'  => '<span class="dashicons dashicons-dismiss"></span><span class="villatheme-hide-toolbar-button-title">Hide VillaTheme toolbar</span>',
    705706                'parent' => 'villatheme',
    706707                'href'   => add_query_arg( array( '_villatheme_nonce' => wp_create_nonce( 'villatheme_hide_toolbar' ) ) ),
     
    941942    }
    942943}
     944
     945if ( ! class_exists( 'VillaTheme_Require_Environment' ) ) {
     946    class VillaTheme_Require_Environment {
     947
     948        protected $args;
     949        protected $plugin_name;
     950        protected $notices = [];
     951
     952        public function __construct( $args ) {
     953            if ( ! did_action( 'plugins_loaded' ) ) {
     954                _doing_it_wrong( 'VillaTheme_Require_Environment', sprintf(
     955                /* translators: %s: plugins_loaded */
     956                    __( 'VillaTheme_Require_Environment should not be run before the %s hook.' ),
     957                    '<code>plugins_loaded</code>'
     958                ), '6.2.0' );
     959            }
     960
     961            $args = wp_parse_args( $args, [
     962                'plugin_name'     => '',
     963                'php_version'     => '',
     964                'wp_version'      => '',
     965                'wc_verison'      => '',
     966                'require_plugins' => [],
     967            ] );
     968
     969            $this->plugin_name = $args['plugin_name'];
     970
     971            $this->check( $args );
     972
     973            add_action( 'admin_notices', [ $this, 'notice' ] );
     974        }
     975
     976        protected function check( $args ) {
     977            if ( ! function_exists( 'install_plugin_install_status' ) ) {
     978                require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     979            }
     980
     981            if ( ! function_exists( 'is_plugin_active' ) ) {
     982                require_once ABSPATH . 'wp-admin/includes/plugin.php';
     983            }
     984
     985            if ( ! empty( $args['php_version'] ) ) {
     986                $compatible_php = is_php_version_compatible( $args['php_version'] );
     987                if ( ! $compatible_php ) {
     988                    $this->notices[] = sprintf( "PHP version at least %s.", esc_html( $args['php_version'] ) );
     989                }
     990            }
     991
     992            if ( ! empty( $args['wp_version'] ) ) {
     993                $compatible_wp = is_wp_version_compatible( $args['wp_version'] );
     994                if ( ! $compatible_wp ) {
     995                    $this->notices[] = sprintf( "WordPress version at least %s.", esc_html( $args['wp_version'] ) );
     996                }
     997            }
     998
     999            if ( ! empty( $args['require_plugins'] ) ) {
     1000                foreach ( $args['require_plugins'] as $plugin ) {
     1001                    if ( empty( $plugin['version'] ) ) {
     1002                        $plugin['version'] = '';
     1003                    }
     1004
     1005                    $status              = install_plugin_install_status( $plugin );
     1006                    $require_plugin_name = $plugin['name'] ?? '';
     1007
     1008                    $requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
     1009                    $requires_wp  = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
     1010
     1011                    $compatible_php = is_php_version_compatible( $requires_php );
     1012                    $compatible_wp  = is_wp_version_compatible( $requires_wp );
     1013
     1014                    if ( ! $compatible_php || ! $compatible_wp ) {
     1015                        continue;
     1016                    }
     1017
     1018                    switch ( $status['status'] ) {
     1019
     1020                        case 'install':
     1021                            $this->notices[] = sprintf( "%s to be installed. <br><a href='%s' target='_blank' class='button button-primary' style='vertical-align: middle; margin-top: 5px;'>Install %s</a>",
     1022                                esc_html( $require_plugin_name ),
     1023                                esc_url( ! empty( $status['url'] ) ? $status['url'] : '#' ),
     1024                                esc_html( $require_plugin_name ) );
     1025
     1026                            break;
     1027
     1028                        default:
     1029
     1030                            if ( ! is_plugin_active( $status['file'] ) && current_user_can( 'activate_plugin', $status['file'] ) ) {
     1031                                $activate_url = add_query_arg(
     1032                                    [
     1033                                        '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
     1034                                        'action'   => 'activate',
     1035                                        'plugin'   => $status['file'],
     1036                                    ],
     1037                                    network_admin_url( 'plugins.php' )
     1038                                );
     1039
     1040                                $this->notices[] = sprintf( "%s is installed and activated. <br> <a href='%s' target='_blank' class='button button-primary' style='vertical-align: middle; margin-top: 5px;'>Active %s</a>",
     1041                                    esc_html( $require_plugin_name ),
     1042                                    esc_url( $activate_url ),
     1043                                    esc_html( $require_plugin_name ) );
     1044
     1045                            }
     1046
     1047                            if ( $plugin['slug'] == 'woocommerce' && ! empty( $args['wc_version'] ) && is_plugin_active( $status['file'] ) ) {
     1048                                $wc_current_version = get_option( 'woocommerce_version' );
     1049                                if ( ! version_compare( $wc_current_version, $args['wc_version'], '>=' ) ) {
     1050                                    $this->notices[] = sprintf( "WooCommerce version at least %s.", esc_html( $args['wc_version'] ) );
     1051                                }
     1052                            }
     1053
     1054                            break;
     1055                    }
     1056                }
     1057            }
     1058        }
     1059
     1060        public function notice() {
     1061            $screen = get_current_screen();
     1062
     1063            if ( ! current_user_can( 'manage_options' ) || $screen->id === 'update' ) {
     1064                return;
     1065            }
     1066
     1067            if ( ! empty( $this->notices ) ) {
     1068                ?>
     1069                <div class="error">
     1070                    <?php
     1071                    if ( count( $this->notices ) > 1 ) {
     1072                        printf( "<p>%s requires:</p>", esc_html( $this->plugin_name ) );
     1073                        ?>
     1074                        <ol>
     1075                            <?php
     1076                            foreach ( $this->notices as $notice ) {
     1077                                printf( "<li>%s</li>", wp_kses_post( $notice ) );
     1078                            }
     1079                            ?>
     1080                        </ol>
     1081                        <?php
     1082                    } else {
     1083                        printf( "<p>%s requires %s</p>", esc_html( $this->plugin_name ), wp_kses_post( current( $this->notices ) ) );
     1084                    }
     1085                    ?>
     1086                </div>
     1087                <?php
     1088            }
     1089        }
     1090
     1091        public function has_error() {
     1092            return ! empty( $this->notices );
     1093        }
     1094    }
     1095}
  • subre-product-subscription-for-woo/trunk/readme.txt

    r2870920 r2984097  
    167167
    168168== Changelog ==
     169
     170/**1.0.2 - 2023.10.26**/
     171– Updated: Compatible with WordPress 6.3 & WooCommerce 8.2
     172
     173/**1.0.1 - 2023.07.03**/
     174– Updated: Compatible with WooCommerce HPOS(COT)
     175
    169176/**1.0.0 - 2023..**/
    170177~ The first released
  • subre-product-subscription-for-woo/trunk/subre-product-subscription-for-woo.php

    r2861966 r2984097  
    44 * Plugin URI: https://villatheme.com/extensions/subre-woocommerce-product-subscription/
    55 * Description: Convert WooCommerce simple products(physical or downloadable/virtual) to subscription products and allow recurring payments
    6  * Version: 1.0.0
     6 * Version: 1.0.2
    77 * Author: VillaTheme(villatheme.com)
    88 * Author URI: http://villatheme.com
    99 * Text Domain: subre-product-subscription-for-woo
    1010 * Copyright 2022 VillaTheme.com. All rights reserved.
    11  * Tested up to: 6.1
    12  * WC tested up to: 7.1
     11 * Tested up to: 6.3
     12 * WC tested up to: 8.2
    1313 * Requires PHP: 7.0
    1414 **/
     
    1616    exit;
    1717}
    18 define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_VERSION', '1.0.0' );
    19 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     18
     19define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_VERSION', '1.0.2' );
    2020define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DIR', plugin_dir_path( __FILE__ ) );
    2121define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES', SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DIR . 'includes' . DIRECTORY_SEPARATOR );
    22 if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
    23     $init_file = SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'define.php';
    24     require_once $init_file;
    25 }
    2622
    2723/**
     
    3228        register_activation_hook( __FILE__, array( $this, 'activate' ) );
    3329        register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
    34         add_action( 'admin_notices', array( $this, 'global_note' ) );
     30        add_action( 'plugins_loaded', array( $this, 'init' ) );
     31        add_action( 'before_woocommerce_init', [ $this, 'custom_order_tables_declare_compatibility' ] );
    3532    }
    3633
    37     public function global_note() {
    38         if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
    39             ?>
    40             <div id="message" class="error">
    41                 <p><?php _e( 'Please install and activate WooCommerce to use SUBRE – Product Subscription for Woo plugin.', 'subre-product-subscription-for-woo' ); ?></p>
    42             </div>
    43             <?php
     34    public function init() {
     35        if ( ! class_exists( 'VillaTheme_Require_Environment' ) ) {
     36            include_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'support.php';
    4437        }
     38
     39        $environment = new \VillaTheme_Require_Environment( [
     40                'plugin_name'     => 'SUBRE – Product Subscription for WooCommerce',
     41                'php_version'     => '7.0',
     42                'wp_version'      => '5.0',
     43                'wc_version'      => '5.0',
     44                'require_plugins' => [
     45                    [
     46                        'slug' => 'woocommerce',
     47                        'name' => 'WooCommerce',
     48                    ],
     49                ]
     50            ]
     51        );
     52
     53        if ( $environment->has_error() ) {
     54            return;
     55        }
     56
     57        if ( is_plugin_active( 'subre-product-subscription-for-woocommerce/subre-product-subscription-for-woocommerce.php' ) ) {
     58            return;
     59        }
     60
     61        require_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'define.php';
    4562    }
    46 
    4763
    4864    /**
     
    5066     */
    5167    public function activate() {
    52         global $wp_version;
    53         if ( version_compare( $wp_version, '5.0', "<" ) ) {
    54             deactivate_plugins( basename( __FILE__ ) ); // Deactivate our plugin
    55             wp_die( 'This plugin requires WordPress version 5.0 or higher.' );
    56         }
    5768        update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
    5869    }
     
    6778        }
    6879    }
     80
     81    public function custom_order_tables_declare_compatibility() {
     82        if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     83            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     84        }
     85    }
    6986}
    7087
Note: See TracChangeset for help on using the changeset viewer.