Plugin Directory

Changeset 3479083


Ignore:
Timestamp:
03/10/2026 12:56:23 PM (3 weeks ago)
Author:
sendpulse
Message:

1.1.7

  • Fix opt-in checkbox consent handling for WooCommerce checkout
  • Improved compatibility with WooCommerce Blocks checkout and HPOS
Location:
sendpulse-subscription-for-woocommerce
Files:
18 added
3 edited

Legend:

Unmodified
Added
Removed
  • sendpulse-subscription-for-woocommerce/trunk/classes/class-wc-integration-sendpulse.php

    r3346815 r3479083  
    2121        private $confirm_opt_checkbox_default_status;
    2222        private $confirm_opt_checkbox_display_location;
     23        private $client = null;
    2324
    2425        /**
     
    7778            });
    7879
    79             add_action('woocommerce_checkout_update_order_meta', array($this, 'order_status_changed'), 1000, 1);
     80            //add_action('woocommerce_checkout_update_order_meta', array($this, 'order_status_changed'), 1000, 1);
    8081            add_action('woocommerce_order_status_changed', array($this, 'order_status_changed'), 10, 3);
    8182            add_filter('woocommerce_checkout_fields', array($this, 'add_checkout_fields'));
     
    209210        }
    210211
    211 //      public function process_admin_options() {
    212 //          // Verify nonce
    213 //          if (
    214 //              !isset($_POST['_wpnonce']) ||
    215 //              !wp_verify_nonce(
    216 //                  sanitize_text_field(wp_unslash($_POST['_wpnonce'])),
    217 //                  'woocommerce-settings'
    218 //              )
    219 //          ) {
    220 //              wp_die(esc_html__('Invalid request. Please refresh the page and try again.', 'sendpulse-subscription-for-woocommerce'));
    221 //          }
    222 //
    223 //          $this->api_id = !empty($_POST['woocommerce_sendpulse_api_id'])
    224 //              ? sanitize_text_field(wp_unslash($_POST['woocommerce_sendpulse_api_id']))
    225 //              : $this->get_option('api_id');
    226 //
    227 //          $this->api_secret = !empty($_POST['woocommerce_sendpulse_api_secret'])
    228 //              ? sanitize_text_field(wp_unslash($_POST['woocommerce_sendpulse_api_secret']))
    229 //              : $this->get_option('api_secret');
    230 //
    231 //          $this->storageType = !empty($_POST['woocommerce_sendpulse_keep_token'])
    232 //              ? sanitize_text_field(wp_unslash($_POST['woocommerce_sendpulse_keep_token']))
    233 //              : $this->get_option('keep_token');
    234 //
    235 //          $previous_keep_token = $this->get_option('keep_token', 'wp_options');
    236 //
    237 //          // Capture parent result
    238 //          $result = parent::process_admin_options();
    239 //
    240 //          if (isset($_POST['woocommerce_sendpulse_keep_token'])) {
    241 //              $new_keep_token = sanitize_text_field(wp_unslash($_POST['woocommerce_sendpulse_keep_token']));
    242 //              update_option('woocommerce_sendpulse_keep_token', $new_keep_token);
    243 //
    244 //              if ($previous_keep_token !== $new_keep_token) {
    245 //                  $this->deleteTokenFromStorage($previous_keep_token);
    246 //              }
    247 //
    248 //              $this->storageType = $new_keep_token;
    249 //          } else {
    250 //              $this->storageType = $previous_keep_token;
    251 //          }
    252 //
    253 //          return $result;
    254 //      }
    255 
    256 //      public function process_admin_options() {
    257 //          // Verify nonce
    258 //          if (
    259 //              !isset($_POST['_wpnonce']) ||
    260 //              !wp_verify_nonce(
    261 //                  sanitize_text_field(wp_unslash($_POST['_wpnonce'])),
    262 //                  'woocommerce-settings'
    263 //              )
    264 //          ) {
    265 //              wp_die(esc_html__('Invalid request. Please refresh the page and try again.', 'sendpulse-subscription-for-woocommerce'));
    266 //          }
    267 //
    268 //          $previous_api_id     = $this->get_option('api_id');
    269 //          $previous_api_secret = $this->get_option('api_secret');
    270 //          $previous_keep_token = $this->get_option('keep_token', 'wp_options');
    271 //
    272 //          $this->api_id = !empty($_POST['woocommerce_sendpulse_api_id'])
    273 //              ? sanitize_text_field(wp_unslash($_POST['woocommerce_sendpulse_api_id']))
    274 //              : $this->get_option('api_id');
    275 //
    276 //          $this->api_secret = !empty($_POST['woocommerce_sendpulse_api_secret'])
    277 //              ? sanitize_text_field(wp_unslash($_POST['woocommerce_sendpulse_api_secret']))
    278 //              : $this->get_option('api_secret');
    279 //
    280 //          $this->storageType = !empty($_POST['woocommerce_sendpulse_keep_token'])
    281 //              ? sanitize_text_field(wp_unslash($_POST['woocommerce_sendpulse_keep_token']))
    282 //              : $this->get_option('keep_token');
    283 //
    284 //          // Save settings normally
    285 //          $result = parent::process_admin_options();
    286 //
    287 //          // If storage type changed, delete token from old storage
    288 //          if (isset($_POST['woocommerce_sendpulse_keep_token'])) {
    289 //              $new_keep_token = sanitize_text_field(wp_unslash($_POST['woocommerce_sendpulse_keep_token']));
    290 //              update_option('woocommerce_sendpulse_keep_token', $new_keep_token);
    291 //
    292 //              if ( $previous_keep_token !== $new_keep_token && ($previous_api_id !== $this->api_id || $previous_api_secret !== $this->api_secret) ) {
    293 //                  $this->deleteTokenFromStorage($previous_keep_token);
    294 //              }
    295 //              $this->storageType = $new_keep_token;
    296 //          } else {
    297 //              $this->storageType = $previous_keep_token;
    298 //          }
    299 //
    300 //          // If API credentials changed, delete token so a new one will be fetched
    301 ////            if ($previous_api_id !== $this->api_id || $previous_api_secret !== $this->api_secret) {
    302 ////                $this->deleteTokenFromStorage($this->storageType);
    303 ////            }
    304 //
    305 //          //$this->getToken();
    306 ////            if (!empty($this->client) && method_exists($this->client, 'getToken')) {
    307 ////                $this->client->getToken();
    308 ////            }
    309 //
    310 //          return $result;
    311 //      }
    312 
    313212        public function process_admin_options() {
    314213            // Verify nonce
     
    496395        }
    497396
    498         public function order_status_changed($id, $old_status = 'new', $new_status = 'pending') {
    499             if ($this->s_api && $this->module_status && $new_status === $this->subscr_time) {
    500                 $order = $this->wc_get_order($id);
    501 
    502                 $subscribe_customer = get_post_meta($id, 'sendpulse-for-woocommerce_confirm_opt', true);
    503 
    504                 if (empty($subscribe_customer) || $subscribe_customer === 'yes') {
    505                     $this->syncUserAbook(
    506                         $order->billing_email,
    507                         $order->billing_first_name,
    508                         $order->billing_last_name,
    509                         $order->billing_phone,
    510                         $order->billing_company,
    511                         $order->billing_country,
    512                         $order->billing_state,
    513                         $order->billing_city
     397        public function order_status_changed( $id, $old_status = 'new', $new_status = 'pending' ) {
     398            // Preconditions
     399            if ( ! $this->s_api || ! $this->module_status ) {
     400                return;
     401            }
     402            if ( $new_status !== $this->subscr_time ) {
     403                return;
     404            }
     405
     406            $order = $this->wc_get_order( $id );
     407            if ( ! $order ) {
     408                return;
     409            }
     410
     411            $consent            = $order->get_meta( 'sendpulse-for-woocommerce_confirm_opt', true ); // 'yes'|'no'|''
     412            $explicit_yes       = ( $consent === 'yes' );
     413            $optin_ui_enabled   = ( 'yes' === $this->show_confirm_opt );
     414            $should_subscribe   = $optin_ui_enabled ? $explicit_yes : true;
     415
     416            if ( ! $should_subscribe ) {
     417                if ( function_exists( 'wc_get_logger' ) ) {
     418                    wc_get_logger()->info(
     419                        sprintf( 'SendPulse: not subscribing order #%d (opt-in required; canonical consent=%s).', $id, var_export( $consent, true ) ),
     420                        [ 'source' => 'sendpulse' ]
    514421                    );
    515422                }
     423                return;
     424            }
     425
     426            // Subscribe using getters
     427            $this->syncUserAbook(
     428                $order->get_billing_email(),
     429                $order->get_billing_first_name(),
     430                $order->get_billing_last_name(),
     431                $order->get_billing_phone(),
     432                $order->get_billing_company(),
     433                $order->get_billing_country(),
     434                $order->get_billing_state(),
     435                $order->get_billing_city()
     436            );
     437
     438            if ( function_exists( 'wc_get_logger' ) ) {
     439                wc_get_logger()->info( sprintf( 'SendPulse: subscribed order #%d.', $id ), [ 'source' => 'sendpulse' ] );
    516440            }
    517441        }
     442
    518443
    519444        private function wc_get_order($order_id) {
     
    526451
    527452        function save_checkout_fields($order_id) {
    528             // Verify nonce
    529             if ( !isset($_POST['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'])), 'woocommerce-settings')) {
    530                 wp_die(esc_html__('Invalid request. Please refresh the page and try again.', 'sendpulse-subscription-for-woocommerce'));
    531             }
     453            // Skip on Store API (Blocks) requests — consent is handled in class-sendpulse-blocks.php
     454
     455            if (
     456                ( defined( 'REST_REQUEST' ) && REST_REQUEST ) &&
     457                isset( $_SERVER['REQUEST_URI'] ) &&
     458                strpos( $_SERVER['REQUEST_URI'], '/wc/store/' ) !== false
     459            ) {
     460                return;
     461            }
    532462
    533463            if ('yes' == $this->show_confirm_opt) {
    534464                $opt_in = isset($_POST['sendpulse-for-woocommerce_confirm_opt']) ? 'yes' : 'no';
    535                 update_post_meta($order_id, 'sendpulse-for-woocommerce_confirm_opt', $opt_in);
     465                $order = $this->wc_get_order( $order_id );
     466                if ( $order ) {
     467                    $order->update_meta_data( 'sendpulse-for-woocommerce_confirm_opt', $opt_in );
     468                    $order->save();
     469                }
    536470            }
    537471        }
  • sendpulse-subscription-for-woocommerce/trunk/readme.txt

    r3473375 r3479083  
    99Tested up to: 6.8
    1010WC requires at least: 6.0
    11 WC tested up to: 10.0.4
    12 Stable tag: 1.1.5
    13 License: GNU General Public License v3.0
    14 License URI: http://www.gnu.org/licenses/gpl-2.0.html
     11WC tested up to: 10.3.8
     12Stable tag: 1.1.7
     13License: GPLv3
     14License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1515
    1616Start email marketing to your customers using SendPulse.
     
    112112
    113113== Changelog ==
     114= 1.1.7 =
     115* Fix opt-in checkbox consent handling for WooCommerce checkout (Blocks and classic checkout compatibility)
     116* Improve consent detection logic for WooCommerce HPOS and Store API
    114117
    115 = 1.1.3 =
    116 * Initial Release to WordPress Plugin's Directory
     118= 1.1.5 =
     119* Fix settings link from WordPress plugins page
    117120
    118121= 1.1.4 =
     
    121124* Tested up to WordPress 6.8.2 and WooCommerce 10.0.4
    122125
    123 = 1.1.5 =
    124 * Fix settings link from WordPress plugins page
     126= 1.1.3 =
     127* Initial Release to WordPress Plugin's Directory
    125128
    126129== Upgrade Notice ==
  • sendpulse-subscription-for-woocommerce/trunk/sendpulse-subscription-for-woocommerce.php

    r3352615 r3479083  
    66 * Author: SendPulse
    77 * Author URI: https://sendpulse.com
    8  * Version: 1.1.5
     8 * Version: 1.1.7
    99 * Text Domain: sendpulse-subscription-for-woocommerce
    1010 * Domain Path: /languages
     
    1919    exit;
    2020}
     21
     22require_once __DIR__ . '/classes/class-sendpulse-blocks.php';
    2123
    2224function add_sendpulse_integration($methods) {
Note: See TracChangeset for help on using the changeset viewer.