Changeset 2984097
- Timestamp:
- 10/26/2023 01:19:56 AM (2 years ago)
- Location:
- subre-product-subscription-for-woo/trunk
- Files:
-
- 15 edited
-
CHANGELOG.txt (modified) (1 diff)
-
admin/admin.php (modified) (1 diff)
-
frontend/cart.php (modified) (3 diffs)
-
frontend/checkout.php (modified) (2 diffs)
-
frontend/product.php (modified) (1 diff)
-
includes/define.php (modified) (1 diff)
-
includes/payment/stripe.php (modified) (4 diffs)
-
includes/payment/stripe_cc.php (modified) (3 diffs)
-
includes/subscription-email.php (modified) (1 diff)
-
includes/subscription-order.php (modified) (8 diffs)
-
includes/subscription-product-helper.php (modified) (8 diffs)
-
includes/subscription-schedule.php (modified) (1 diff)
-
includes/support.php (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
-
subre-product-subscription-for-woo.php (modified) (5 diffs)
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 1 7 /**1.0.0 - 2023.02.08**/ 2 8 ~ The first released -
subre-product-subscription-for-woo/trunk/admin/admin.php
r2861966 r2984097 41 41 'slug' => 'subre-product-subscription-for-woo', 42 42 'menu_slug' => 'subre-product-subscription-for-woo', 43 'survey_url' => ' ',43 'survey_url' => 'https://script.google.com/macros/s/AKfycbzFUSL8LQlMK65VltDG1a-JVESk8IlYQSSgAvhSJLWH47obp8NA3MDUSgSS8z9iIwNgXA/exec', 44 44 'version' => SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_VERSION 45 45 ) -
subre-product-subscription-for-woo/trunk/frontend/cart.php
r2865411 r2984097 14 14 add_filter( 'woocommerce_cart_item_price', array( $this, 'change_subscription_price_html_in_cart' ), 10, 3 ); 15 15 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 ); 20 17 /*Change subscription price while calculating total*/ 21 18 add_action( 'woocommerce_before_calculate_totals', array( $this, 'add_calculation_price_filter' ) ); 22 19 add_action( 'woocommerce_calculate_totals', array( $this, 'remove_calculation_price_filter' ) ); 23 20 add_action( 'woocommerce_after_calculate_totals', array( $this, 'remove_calculation_price_filter' ) ); 21 add_action( 'woocommerce_cart_calculate_fees', [ $this, 'add_signup_fee' ] ); 24 22 } 25 23 … … 73 71 * 74 72 * @return array|mixed|string 73 * @throws Exception 75 74 */ 76 75 public function change_subscription_price_html_in_cart( $price, $cart_item, $cart_item_key ) { … … 122 121 return $contains_subscription; 123 122 } 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 } 124 153 } -
subre-product-subscription-for-woo/trunk/frontend/checkout.php
r2865411 r2984097 81 81 $args = array( 82 82 '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' ), 87 84 'posts_per_page' => - 1, 88 85 'post_parent' => $order_id, … … 124 121 * @return float|int|string 125 122 */ 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 // } 145 142 } -
subre-product-subscription-for-woo/trunk/frontend/product.php
r2861966 r2984097 67 67 * 68 68 * @return mixed 69 * @throws Exception 69 70 */ 70 71 public static function maybe_change_price_html( $price, $product ) { -
subre-product-subscription-for-woo/trunk/includes/define.php
r2861966 r2984097 19 19 define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_IMAGES', SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_ASSETS . "images/" ); 20 20 require_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'functions.php'; 21 require_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'support.php';22 21 require_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'data.php'; 23 22 require_once SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES . 'subscription-product-helper.php'; -
subre-product-subscription-for-woo/trunk/includes/payment/stripe.php
r2865411 r2984097 15 15 add_action( 'subre_renewal_order_payment_due', array( $this, 'handle_payment' ), 10, 2 ); 16 16 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 ); 29 20 } 30 21 … … 125 116 126 117 public static function get_supported_payment_methods() { 127 return array( 128 'stripe', 129 'stripe_sepa' 130 ); 118 return array( 'stripe', 'stripe_sepa' ); 131 119 } 132 120 … … 135 123 * @param bool $retry 136 124 * @param bool $previous_error 125 * 126 * @throws WC_Data_Exception 137 127 */ 138 128 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' ) ) ) { 143 130 $stripe_order_handler = WC_Stripe_Order_Handler::get_instance(); 144 131 try { … … 168 155 */ 169 156 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 ); 174 158 } 175 159 -
subre-product-subscription-for-woo/trunk/includes/payment/stripe_cc.php
r2865411 r2984097 14 14 add_filter( 'wc_stripe_should_save_payment_method', array( $this, 'should_save_payment_method' ), 10, 3 ); 15 15 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 ); 28 19 } 29 20 … … 141 132 142 133 /** 143 * @param $renewal_order WC_Order 134 * @param WC_Order $renewal_order 135 * 136 * @throws \Stripe\Exception\ApiErrorException 144 137 */ 145 138 public function process_subscription_payment( $renewal_order ) { … … 149 142 $gateway = WC_Stripe_Gateway::load(); 150 143 $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 ) );156 144 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 ) ); 164 150 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; 174 153 } 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 // } 175 169 } catch ( WC_Stripe_Exception $e ) { 176 170 do_action( 'subre_renewal_order_payment_stripe_cc_failed', $renewal_order, $e ); -
subre-product-subscription-for-woo/trunk/includes/subscription-email.php
r2861966 r2984097 78 78 return; 79 79 } 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 ) ) { 84 81 $args = array( 85 82 'post_type' => 'subre_subscription', -
subre-product-subscription-for-woo/trunk/includes/subscription-order.php
r2865411 r2984097 9 9 public function __construct() { 10 10 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 ); 23 17 } 24 18 … … 165 159 return new WP_Error( 'subre_error_invalid_order', esc_html__( 'Not a valid WooCommerce order object', 'subre-product-subscription-for-woo' ) ); 166 160 } 161 167 162 if ( ! SUBRE_SUBSCRIPTION_PRODUCT_HELPER::is_subscription( $product_id ) ) { 168 163 return new WP_Error( 'subre_error_not_a_subcription_product', esc_html__( 'Not a subscription product', 'subre-product-subscription-for-woo' ) ); 169 164 } 165 170 166 $order_id = $order->get_id(); 171 167 if ( self::subscription_exists_in_order( $order_id, $product_id ) ) { 172 168 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' ) ); 173 169 } 170 174 171 $order_items = $order->get_items(); 175 172 $line_item_id = ''; 173 176 174 foreach ( $order_items as $item_id => $order_item ) { 177 175 if ( $order_item->get_product_id() == $product_id ) { … … 181 179 } 182 180 } 181 183 182 if ( ! isset( $product ) ) { 184 183 return new WP_Error( 'subre_error_product_not_existing_in_order', esc_html__( 'Product not existing in order', 'subre-product-subscription-for-woo' ) ); 185 184 } 185 186 186 $date_created = $order->get_date_created(); 187 187 $subscription = new WC_Order(); … … 192 192 $subscription_ids = array(); 193 193 } 194 194 195 $sign_up_fee = get_post_meta( $product_id, '_subre_product_sign_up_fee', true ); 195 196 $subscription_period = get_post_meta( $product_id, '_subre_product_period', true ); 196 197 $subscription_period_unit = get_post_meta( $product_id, '_subre_product_period_unit', true ); 198 197 199 if ( $override_trial === false ) { 198 200 $trial_period = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_subscription_trial_period( $product ); … … 200 202 $trial_period = $override_trial; 201 203 } 204 202 205 $trial_period_unit = get_post_meta( $product_id, '_subre_product_trial_period_unit', true ); 203 206 $expire_after = get_post_meta( $product_id, '_subre_product_expire_after', true ); … … 249 252 $clone = clone $product_line; 250 253 $clone->set_id( 0 ); 254 251 255 if ( $trial_period ) { 252 256 /*If trial, do not copy line product item total from order*/ … … 256 260 $total = $product_line->get_total(); 257 261 } 262 258 263 $subscription->add_item( $clone ); 259 264 $subscription->set_total( $total + $order->get_shipping_total() ); … … 273 278 } 274 279 } 280 275 281 self::copy_main_order_data( $subscription, $order ); 276 282 self::copy_payment_method( $subscription, $order ); -
subre-product-subscription-for-woo/trunk/includes/subscription-product-helper.php
r2865411 r2984097 54 54 if ( self::is_subscription( $product ) ) { 55 55 $instance = SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_instance(); 56 56 57 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' ) ); 61 59 $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 ); 66 61 } 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 ); 68 68 $price = wc_price( $price ); 69 69 } 70 70 71 $sign_up_fee = self::get_product_sign_up_fee( $product ); 71 72 $subscription_period = $product->get_meta( '_subre_product_period', true ); … … 79 80 $price_html_with_trial_and_sign_up_fee = $instance->get_params( 'price_html_with_trial_and_sign_up_fee' ); 80 81 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 ); 92 97 } 93 98 } else { … … 95 100 $price_html_with_trial = $instance->get_params( 'price_html_with_trial' ); 96 101 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 ); 106 115 } 107 116 } elseif ( $sign_up_fee ) { 108 117 $price_html_with_sign_up_fee = $instance->get_params( 'price_html_with_sign_up_fee' ); 109 118 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 ); 119 132 } 120 133 } else { 121 134 $price_html = $instance->get_params( 'price_html' ); 122 135 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 133 151 if ( $expire_after ) { 134 152 $expiry_date_info = $instance->get_params( 'expiry_date_info' ); … … 138 156 $expire_after_unit = $subscription_period_unit; 139 157 } 158 140 159 switch ( $expire_after_unit ) { 141 160 case 'year': … … 153 172 break; 154 173 } 174 155 175 $expiry_date = time() + $expire_after * self::get_unit_in_seconds( $expire_after_unit ); 176 156 177 if ( $trial_period ) { 157 178 $expiry_date += $trial_period * self::get_unit_in_seconds( $trial_period_unit ); 158 179 } 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 ); 171 196 } 172 197 … … 199 224 */ 200 225 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 ) ); 206 227 } 207 228 … … 212 233 */ 213 234 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 ); 227 236 } 228 237 … … 269 278 public static function get_product_sign_up_fee( $product ) { 270 279 $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 ] ); 271 281 if ( $sign_up_fee ) { 272 282 $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 169 169 170 170 $renewal_order = wc_get_order( $renewal_id ); 171 171 172 if ( $renewal_order ) { 172 173 if ( ! $renewal_order->is_paid() ) { -
subre-product-subscription-for-woo/trunk/includes/support.php
r2861966 r2984097 8 8 /** 9 9 * Class VillaTheme_Support 10 * 1.1. 710 * 1.1.8 11 11 */ 12 12 class VillaTheme_Support { 13 13 protected $plugin_base_name; 14 14 protected $ads_data; 15 protected $version = '1.1.7'; 15 protected $version = '1.1.8'; 16 protected $data = []; 16 17 17 18 public function __construct( $data ) { … … 702 703 $wp_admin_bar->add_node( array( 703 704 '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>', 705 706 'parent' => 'villatheme', 706 707 'href' => add_query_arg( array( '_villatheme_nonce' => wp_create_nonce( 'villatheme_hide_toolbar' ) ) ), … … 941 942 } 942 943 } 944 945 if ( ! 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 167 167 168 168 == 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 169 176 /**1.0.0 - 2023..**/ 170 177 ~ The first released -
subre-product-subscription-for-woo/trunk/subre-product-subscription-for-woo.php
r2861966 r2984097 4 4 * Plugin URI: https://villatheme.com/extensions/subre-woocommerce-product-subscription/ 5 5 * Description: Convert WooCommerce simple products(physical or downloadable/virtual) to subscription products and allow recurring payments 6 * Version: 1.0. 06 * Version: 1.0.2 7 7 * Author: VillaTheme(villatheme.com) 8 8 * Author URI: http://villatheme.com 9 9 * Text Domain: subre-product-subscription-for-woo 10 10 * Copyright 2022 VillaTheme.com. All rights reserved. 11 * Tested up to: 6. 112 * WC tested up to: 7.111 * Tested up to: 6.3 12 * WC tested up to: 8.2 13 13 * Requires PHP: 7.0 14 14 **/ … … 16 16 exit; 17 17 } 18 define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_VERSION', '1.0.0' ); 19 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );18 19 define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_VERSION', '1.0.2' ); 20 20 define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DIR', plugin_dir_path( __FILE__ ) ); 21 21 define( '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 }26 22 27 23 /** … … 32 28 register_activation_hook( __FILE__, array( $this, 'activate' ) ); 33 29 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' ] ); 35 32 } 36 33 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'; 44 37 } 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'; 45 62 } 46 47 63 48 64 /** … … 50 66 */ 51 67 public function activate() { 52 global $wp_version;53 if ( version_compare( $wp_version, '5.0', "<" ) ) {54 deactivate_plugins( basename( __FILE__ ) ); // Deactivate our plugin55 wp_die( 'This plugin requires WordPress version 5.0 or higher.' );56 }57 68 update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' ); 58 69 } … … 67 78 } 68 79 } 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 } 69 86 } 70 87
Note: See TracChangeset
for help on using the changeset viewer.