Plugin Directory

Changeset 3251915


Ignore:
Timestamp:
03/06/2025 11:27:37 PM (13 months ago)
Author:
marknokes
Message:

2.4.7

  • Feature: add subscription start time to order details
  • Bugfix: plans not updating in gui on plugin activation when using redis cache
  • Bugfix: plugin reactivation causes database error on upgrade
  • Improvement: increase timeout for wp_remote_request
  • Improvement: isset check for plan_id and product_id in ajax actions
  • Improvement: change Order set_taxes method from private to public static
Location:
subscriptions-for-woo
Files:
44 added
11 edited

Legend:

Unmodified
Added
Removed
  • subscriptions-for-woo/trunk/classes/PPSFWOO/class-ppsfwoo-ajax-actions-priv.php

    r3243512 r3251915  
    3434    public static function refresh_plans()
    3535    {
     36        $wait = 10;
     37
     38        if(true === get_transient('ppsfwoo_refresh_plans_ran')) {
     39
     40            return wp_json_encode([
     41                'error' => 'Please wait at least ' . absint($wait) . ' seconds and try again.'
     42            ]);
     43
     44        }
     45
    3646        if(!is_super_admin() && !current_user_can('ppsfwoo_manage_settings')) {
    3747
     
    4252        }
    4353
     54        set_transient('ppsfwoo_refresh_plans_ran', true, $wait);
     55
    4456        $Plan = new Plan();
    4557
     
    4860        return wp_json_encode([
    4961            "success" => !empty($plans),
    50             "plans"   => $plans
     62            "length"   => sizeof($plans)
    5163        ]);
    5264    }
  • subscriptions-for-woo/trunk/classes/PPSFWOO/class-ppsfwoo-ajax-actions.php

    r3251356 r3251915  
    5757            $plan_id = get_post_meta($product_id, "{$PluginMain->env['env']}_ppsfwoo_plan_id", true) ?? NULL;
    5858
    59             $Plan = isset($product_id) ? new Plan($plan_id): NULL;
     59            $Plan = isset($product_id, $plan_id) ? new Plan($plan_id): NULL;
    6060
    61             if(isset($Plan) && $Plan->id) {
     61            if(isset($Plan)) {
    6262
    6363                $response = [
  • subscriptions-for-woo/trunk/classes/PPSFWOO/class-ppsfwoo-database.php

    r3251356 r3251915  
    4646    public static function install()
    4747    {
     48        if((new self("SHOW TABLES LIKE '{$GLOBALS['wpdb']->base_prefix}ppsfwoo_subscriber';"))->result)
     49
     50            return;
     51
    4852        new self("CREATE TABLE IF NOT EXISTS {$GLOBALS['wpdb']->base_prefix}ppsfwoo_subscriber (
    4953          id varchar(64) NOT NULL,
     
    7579        $this_version = PluginMain::plugin_data('Version');
    7680
    77         if($installed_version === $this_version) {
    78 
    79             return;
    80 
    81         }
     81        if($installed_version === $this_version) return;
    8282
    8383        if (version_compare($installed_version, '2.4.1', '<')) {
  • subscriptions-for-woo/trunk/classes/PPSFWOO/class-ppsfwoo-order.php

    r3251356 r3251915  
    9494        $item = new \WC_Order_Item_Product();
    9595
     96        if(1 === $sequence) {
     97
     98            $start_time =  (new \DateTime(self::$Subscriber->subscription->start_time))->format('l, F j, Y');
     99           
     100            $name = " $name starts $start_time";
     101
     102        }
     103
    96104        $item->set_name($name);
    97105
     
    226234    }
    227235
    228     private static function set_taxes($item)
    229     {
    230         $taxes = \WC_Tax::get_rates_for_tax_class(self::$tax_rate_data['tax_rate_slug']);
     236    public static function set_taxes($item, $tax_rate_data = NULL)
     237    {
     238        $tax_rate_data = $tax_rate_data ?? self::$tax_rate_data;
     239
     240        $taxes = \WC_Tax::get_rates_for_tax_class($tax_rate_data['tax_rate_slug']);
    231241
    232242        $found_rate = NULL;
    233243
    234         if(self::$tax_rate_data['tax_rate'] === 0 || !empty(self::$tax_rate_data['inclusive']) || !$taxes)
     244        if($tax_rate_data['tax_rate'] === 0 || !empty($tax_rate_data['inclusive']) || !$taxes)
    235245        {
    236246            $item->set_tax_class("");
     
    241251        foreach ($taxes as $tax_rate_object)
    242252        {
    243             if(self::$tax_rate_data['tax_rate'] === $tax_rate_object->tax_rate) {
     253            if($tax_rate_data['tax_rate'] === $tax_rate_object->tax_rate) {
    244254
    245255                $found_rate = $tax_rate_object;
     
    271281        $subtotal_taxes = \WC_Tax::calc_tax($item->$get_subtotal(), $tax_rates, false);
    272282
    273         $item->set_tax_class(self::$tax_rate_data['tax_rate_slug']);
     283        $item->set_tax_class($tax_rate_data['tax_rate_slug']);
    274284       
    275285        $item->set_taxes([
  • subscriptions-for-woo/trunk/classes/PPSFWOO/class-ppsfwoo-pay-pal.php

    r3248728 r3251915  
    115115        $args = [
    116116            'method'  => $method,
     117            'timeout' => 10,
    117118            'headers' => array_merge([
    118119                'Authorization' => 'Bearer ' . $token,
  • subscriptions-for-woo/trunk/classes/PPSFWOO/class-ppsfwoo-plan.php

    r3251364 r3251915  
    173173                foreach($plan_data['response']['plans'] as $plan)
    174174                {
    175                     if($PluginMain->ppsfwoo_hide_inactive_plans && "ACTIVE" !== $plan['status']) {
     175                    if($PluginMain::get_option('ppsfwoo_hide_inactive_plans') && "ACTIVE" !== $plan['status']) {
    176176
    177177                        continue;
     
    183183                        $product_data = PayPal::request(PayPal::EP_PRODUCTS . $plan['product_id']);
    184184
    185                         $product_name = $product_data['response']['name'];
     185                        $product_name = $product_data['response']['name'] ?? "";
    186186
    187187                        $products[$plan['product_id']] = $product_name;
     
    223223        ]);
    224224
    225         return $plans;
     225        return $PluginMain::get_option('ppsfwoo_plans');
    226226    }
    227227
  • subscriptions-for-woo/trunk/classes/PPSFWOO/class-ppsfwoo-plugin-main.php

    r3248728 r3251915  
    5757            'name'    => 'Hide inactive plans',
    5858            'type'    => 'checkbox',
    59             'default' => 0,
     59            'default' => 1,
    6060            'description' => 'Choose to show/hide inactive PayPal plans on the Plans tab.',
    6161            'sanitize_callback' => 'absint'
     
    183183           $ppsfwoo_resubscribe_landing_page_id,
    184184           $ppsfwoo_discount_apply_to_trial,
    185            $ppsfwoo_discount_waive_setup_fee,
    186185           $ppsfwoo_discount,
    187186           $template_dir,
     
    258257
    259258        add_action('ppsfwoo_after_options_page', [$this, 'after_options_page']);
     259
     260        add_action('woocommerce_order_item_meta_end', [$this, 'update_receipt_line_item_totals'], 10, 3 );
    260261    }
    261262
     
    268269        add_filter('wp_new_user_notification_email', [$this, 'new_user_notification_email'], 10, 4);
    269270
    270         add_filter('woocommerce_get_order_item_totals', [$this, 'update_receipt_display'], 10, 2);
    271 
     271        add_filter('woocommerce_get_order_item_totals', [$this, 'update_receipt_subtotal'], 10, 2);
     272
     273        add_filter('woocommerce_email_recipient_customer_processing_order', [$this, 'suppress_processing_order_email'], 10, 2 );
     274    }
     275
     276    public function suppress_processing_order_email($recipient, $order)
     277    {
     278        if(Order::has_subscription($order)) {
     279
     280            return '';
     281
     282        }
     283
     284        return $recipient;
     285    }
     286
     287    public function update_receipt_line_item_totals($item_id, $item, $order)
     288    {
     289        if(!Order::has_subscription($order)) {
     290
     291            return;
     292
     293        }
     294
     295        $meta = $item->get_meta('exclude_from_order_total')['value'] ?? '';
     296
     297        $exclude_from_order_total = $meta === 'yes';
     298
     299        if($exclude_from_order_total) {
     300
     301            $item->set_subtotal($item->get_total());
     302       
     303        }
    272304    }
    273305
     
    283315    }
    284316
    285     public function update_receipt_display($totals, $order)
     317    public function update_receipt_subtotal($totals, $order)
    286318    {
    287319        if(!Order::has_subscription($order)) {
     
    348380        self::clear_option_cache($option_name);
    349381
    350         if(
    351             'ppsfwoo_hide_inactive_plans' === $option_name &&
    352             false === get_transient('ppsfwoo_refresh_plans_ran')
    353         ) {
    354 
    355             set_transient('ppsfwoo_refresh_plans_ran', true, 10);
     382        if('ppsfwoo_hide_inactive_plans' === $option_name) {
    356383
    357384            AjaxActionsPriv::refresh_plans();
  • subscriptions-for-woo/trunk/js/main.js

    r3126531 r3251915  
    3434        ppsfwooDoAjax('refresh_plans', function(r) {
    3535            var response = JSON.parse(r);
    36             if(0 === response.plans.length) {
     36            if(0 === response.length) {
    3737                ppsfwooShowMsg("No plans found.", "warning");
    3838            } else if(response.success) {
    3939                ppsfwooShowMsg("Successfully refreshed plans.");
    4040                ppsfwooRefreshPage();
     41            } else if(response.error) {
     42                ppsfwooShowMsg(response.error, "error");
    4143            } else {
    4244                ppsfwooShowMsg(settingsError, "error");
  • subscriptions-for-woo/trunk/js/main.min.js

    r3126531 r3251915  
    1 jQuery(document).ready(function(n){var a,t="There has been an error. Please try again and check your <a href='"+ppsfwoo_ajax_var.settings_url+"'>WooCommerce PayPal Payments settings</a>.";function i(e="",t="success"){n("#wpcontent").prepend(`<div style="z-index: 9999; position: fixed; width: 82%" class="notice notice-${t} is-dismissible single-cached"><p>${e}</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>`),setTimeout(function(){n(".notice-dismiss").parent().fadeOut("slow",function(){n(this).remove()})},5e3),n(".notice-dismiss").click(function(e){n(this).parent().remove()})}function s(e,t,a={}){e={action:"ppsfwoo_admin_ajax_callback",method:e};n.isEmptyObject(a)||(e=n.extend({},e,a)),n.ajax({type:"POST",url:"/wp-admin/admin-ajax.php",data:e,success:t})}function o(e="tab-plans"){var t=r(window.location.href);window.location.href=t+"&tab="+e}function r(e){var t,a=e.split("?");return 2<=a.length?(t=a[1].split("&").filter(function(e){return!e.startsWith("subs_page_num=")&&!e.startsWith("tab=")}),a[0]+"?"+t.join("&")):e}function c(e){var t=document.createElement("div"),a=(t.setAttribute("role","overlay"),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t.style.backgroundColor="rgba(0, 0, 0, 0.5)",t.style.zIndex="1000",document.createElement("div"));a.style.position="absolute",a.style.top="50%",a.style.left="50%",a.style.transform="translate(-50%, -50%)",a.style.backgroundColor="white",a.style.padding="20px",a.style.borderRadius="5px",a.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.3)",a.textContent=e||"Please wait...",t.appendChild(a),document.body.appendChild(t)}function l(){var e=document.querySelector('div[role="overlay"]');e&&e.parentNode.removeChild(e)}n("a.deactivate, a.activate").click(function(e){e.preventDefault(),c("Processing...");var e=n(this).data("plan-id"),t=n(this).data("nonce");s("modify_plan",function(e){e=JSON.parse(e);(e.error?(alert(e.error),l):o)()},{plan_id:e,paypal_action:n(this).attr("class"),nonce:t})}),n(".plan-row").on("click",".copy-button",function(e){var t=n(this).prev(".copy-text"),a=n("<textarea>");a.val(t.text()),n("body").append(a),a.select(),a[0].setSelectionRange(0,99999),document.execCommand("copy"),a.remove(),alert("Copied to clipboard: "+t.text()),e.preventDefault()}),l(),n("#subs-search").on("submit",function(e){e.preventDefault(),s("search_subscribers",function(e){e=JSON.parse(e);e.error?i(e.error,"warning"):(n("#tab-subscribers .pagination, .button.export-table-data").hide(),n("#reset").show(),n("#subscribers").replaceWith(e.html))},{email:n("#email-input").val(),search_by_email:n("#search_by_email").val()})}),n("#refresh").click(function(e){e.preventDefault(),c("Processing..."),s("refresh_plans",function(e){e=JSON.parse(e);0===e.plans.length?i("No plans found.","warning"):e.success?(i("Successfully refreshed plans."),o()):i(t,"error"),l()})}),n(".nav-tab-wrapper a").click(function(e){e.preventDefault(),n(".nav-tab").removeClass("nav-tab-active"),n(this).addClass("nav-tab-active"),n(".tab-content").hide(),a=n(this).attr("href"),n("#"+a).show()}),(n(".nav-tab-wrapper a").hasClass("nav-tab-active")?n(".nav-tab-wrapper a.nav-tab-active"):n(".nav-tab-wrapper a:first-child")).click(),n("#ppsfwoo_options").submit(function(e){var t=r(($element=n(this).find("input[name=_wp_http_referer]")).attr("value"));$element.attr("value",t+"&tab="+a)}),n("input[name=ppsfwoo_delete_plugin_data]").click(function(e){if(n(this).is(":checked"))return confirm("Selecting this option will delete plugin options and the subscribers table on plugin deactivation. Are you sure you want to do this?\n\nThe setting will take effect after you 'Save Changes' below.")})});
     1jQuery(document).ready(function(n){var a,t="There has been an error. Please try again and check your <a href='"+ppsfwoo_ajax_var.settings_url+"'>WooCommerce PayPal Payments settings</a>.";function i(e="",t="success"){n("#wpcontent").prepend(`<div style="z-index: 9999; position: fixed; width: 82%" class="notice notice-${t} is-dismissible single-cached"><p>${e}</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>`),setTimeout(function(){n(".notice-dismiss").parent().fadeOut("slow",function(){n(this).remove()})},5e3),n(".notice-dismiss").click(function(e){n(this).parent().remove()})}function s(e,t,a={}){e={action:"ppsfwoo_admin_ajax_callback",method:e};n.isEmptyObject(a)||(e=n.extend({},e,a)),n.ajax({type:"POST",url:"/wp-admin/admin-ajax.php",data:e,success:t})}function r(e="tab-plans"){var t=o(window.location.href);window.location.href=t+"&tab="+e}function o(e){var t,a=e.split("?");return 2<=a.length?(t=a[1].split("&").filter(function(e){return!e.startsWith("subs_page_num=")&&!e.startsWith("tab=")}),a[0]+"?"+t.join("&")):e}function c(e){var t=document.createElement("div"),a=(t.setAttribute("role","overlay"),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t.style.backgroundColor="rgba(0, 0, 0, 0.5)",t.style.zIndex="1000",document.createElement("div"));a.style.position="absolute",a.style.top="50%",a.style.left="50%",a.style.transform="translate(-50%, -50%)",a.style.backgroundColor="white",a.style.padding="20px",a.style.borderRadius="5px",a.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.3)",a.textContent=e||"Please wait...",t.appendChild(a),document.body.appendChild(t)}function l(){var e=document.querySelector('div[role="overlay"]');e&&e.parentNode.removeChild(e)}n("a.deactivate, a.activate").click(function(e){e.preventDefault(),c("Processing...");var e=n(this).data("plan-id"),t=n(this).data("nonce");s("modify_plan",function(e){e=JSON.parse(e);(e.error?(alert(e.error),l):r)()},{plan_id:e,paypal_action:n(this).attr("class"),nonce:t})}),n(".plan-row").on("click",".copy-button",function(e){var t=n(this).prev(".copy-text"),a=n("<textarea>");a.val(t.text()),n("body").append(a),a.select(),a[0].setSelectionRange(0,99999),document.execCommand("copy"),a.remove(),alert("Copied to clipboard: "+t.text()),e.preventDefault()}),l(),n("#subs-search").on("submit",function(e){e.preventDefault(),s("search_subscribers",function(e){e=JSON.parse(e);e.error?i(e.error,"warning"):(n("#tab-subscribers .pagination, .button.export-table-data").hide(),n("#reset").show(),n("#subscribers").replaceWith(e.html))},{email:n("#email-input").val(),search_by_email:n("#search_by_email").val()})}),n("#refresh").click(function(e){e.preventDefault(),c("Processing..."),s("refresh_plans",function(e){e=JSON.parse(e);0===e.length?i("No plans found.","warning"):e.success?(i("Successfully refreshed plans."),r()):e.error?i(e.error,"error"):i(t,"error"),l()})}),n(".nav-tab-wrapper a").click(function(e){e.preventDefault(),n(".nav-tab").removeClass("nav-tab-active"),n(this).addClass("nav-tab-active"),n(".tab-content").hide(),a=n(this).attr("href"),n("#"+a).show()}),(n(".nav-tab-wrapper a").hasClass("nav-tab-active")?n(".nav-tab-wrapper a.nav-tab-active"):n(".nav-tab-wrapper a:first-child")).click(),n("#ppsfwoo_options").submit(function(e){var t=o(($element=n(this).find("input[name=_wp_http_referer]")).attr("value"));$element.attr("value",t+"&tab="+a)}),n("input[name=ppsfwoo_delete_plugin_data]").click(function(e){if(n(this).is(":checked"))return confirm("Selecting this option will delete plugin options and the subscribers table on plugin deactivation. Are you sure you want to do this?\n\nThe setting will take effect after you 'Save Changes' below.")})});
  • subscriptions-for-woo/trunk/readme.txt

    r3251356 r3251915  
    44License: GPLv2 or later
    55License URI: http://www.gnu.org/licenses/gpl-2.0.html
    6 Stable tag: 2.4.6
     6Stable tag: 2.4.7
    77WC tested up to: 9.7.1
    88Requires at least: 6.4.3
     
    106106== Changelog ==
    107107
     108= 2.4.7 =
     109* Feature: add subscription start time to order details
     110* Bugfix: plans not updating in gui on plugin activation when using redis cache
     111* Bugfix: plugin reactivation causes database error on upgrade
     112* Improvement: increase timeout for wp_remote_request
     113* Improvement: isset check for plan_id and product_id in ajax actions
     114* Improvement: change Order set_taxes method from private to public static
     115
    108116= 2.4.6 =
    109117* Feature: Allow applying different tax rates to woocommerce order based on paypal plan definition
  • subscriptions-for-woo/trunk/subscriptions-for-woo.php

    r3251356 r3251915  
    88 * License: GPLv2 or later
    99 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    10  * Version: 2.4.6
     10 * Version: 2.4.7
    1111 * WC requires at least: 8.6.0
    1212 * WC tested up to: 9.7.1
Note: See TracChangeset for help on using the changeset viewer.