Plugin Directory

Changeset 2636643


Ignore:
Timestamp:
11/29/2021 05:37:29 AM (4 years ago)
Author:
agechecker
Message:
  • Set customer role (if set) to newly created accounts made through guest orders.
  • Give option to assign roles to existing accounts based on email and billing info from guest order.
Location:
agecheckernet/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • agecheckernet/trunk/agechecker.php

    r2628388 r2636643  
    44Plugin URI:  https://agechecker.net
    55Description: AgeChecker.Net seamlessly and securely verifies the age of your customers directly on your website during the checkout process. Keep your site up to date on the latest age regulations for your industry while ensuring that purchasing is frustration-free for your site users.
    6 Version:     1.7.2
     6Version:     1.7.3
    77Author:      AgeChecker.Net
    88Author URI:  https://agechecker.net
  • agecheckernet/trunk/class-wc-integration-agechecker-integration.php

    r2628388 r2636643  
    6969            $this->tag_order           = $this->get_option('tag_order');
    7070            $this->set_customer_role   = $this->get_option('set_customer_role');
     71            $this->role_find_account   = $this->get_option('role_find_account');
    7172
    7273            // Set settings to version without entity codes.
     
    207208                    'title'       => 'Set Customer Role',
    208209                    'type'        => 'selectbox',
    209                     'description' => 'Add a role to a logged-in customer\'s list of user roles upon accepted verification. (Customers must be logged in to their account for the role to be added)',
     210                    'description' => 'Add a role to a logged-in or newly created customer\'s list of user roles upon accepted verification. (Customers must be logged in to their account for the role to be added)',
    210211                    'default'     => 'do_not_set_role',
    211212                    'list'        => 'customer_role',
     213                    'desc_tip'    => false,
     214                ),
     215                'role_find_account'           => array(
     216                    'type'        => 'radio',
     217                    'description' => 'If first option is enabled, a user\'s account will be attempted to be found based on a guest order\'s email and billing details. If matching, the role will be applied to the found user account.',
     218                    'default'     => 'false',
    212219                    'desc_tip'    => false,
    213220                ),
     
    354361                                    <input type="radio" id="<?php echo esc_attr($field); ?>" name="<?php echo esc_attr($field); ?>" value="head" <?php if($script_location_choice == "head") echo 'checked'; ?>> Head<br>
    355362                                    <input type="radio" id="<?php echo esc_attr($field); ?>" name="<?php echo esc_attr($field); ?>" value="footer" <?php if($script_location_choice == "footer") echo 'checked'; ?>> Footer<br>
     363                            <?php
     364                                } else if($key == "role_find_account") {
     365                                    $find_account_choice = $this->get_option($key);
     366                                ?>
     367                                    <input type="radio" id="<?php echo esc_attr($field); ?>" name="<?php echo esc_attr($field); ?>" value="true" <?php if($find_account_choice == "true") echo 'checked'; ?>> Attempt to find user account based on guest order details<br>
     368                                    <input type="radio" id="<?php echo esc_attr($field); ?>" name="<?php echo esc_attr($field); ?>" value="false" <?php if($find_account_choice == "false") echo 'checked'; ?>> Only use user accounts associated with orders<br>
    356369                            <?php
    357370                                } else if($key == "workflow_type") {
     
    836849                        $res = json_decode($post['body']);
    837850                        if ($res->status == "accepted") {
    838                             $user = wp_get_current_user();
    839                             if($user && $user->ID !== 0) {
    840                                 $this->set_verified_role($user);
    841                             }
    842851                            return true;
    843852                        } else {
     
    852861        public function add_verified_notes( $order_id ) {
    853862            $order = new WC_Order( $order_id );
     863
     864            if(!isset($_POST['agechecker_uuid'])) return;
     865           
     866            // Not order tagging logic, but we set this here for before_payment logic
     867            // so users that are created after an order is created are correctly set
     868            // with the role.
     869            if($this->workflow_type == "before_payment") {
     870                $this->set_verified_role($order);
     871            }
    854872           
    855             if(isset($_POST['agechecker_uuid']) && isset($this->tag_order)) {
     873            if(isset($this->tag_order)) {
    856874                if($this->tag_order == "tag_notes" || $this->tag_order == "tag_both") {
    857875                    $note = __("Age Verified order. \n\nAgeChecker UUID: ". $_POST['agechecker_uuid']);
     
    12141232        public function add_script_afterpayment($order_id) {
    12151233            $order = new WC_Order($order_id);
     1234
    12161235            if ($this->is_excluded($order->get_items()) || $this->is_shipping_excluded()) {
    12171236                return;
     
    13341353        }
    13351354
    1336         public function set_verified_role($user) {
     1355        public function set_verified_role($order) {
     1356            if($this->set_customer_role == 'do_not_set_role') return;
     1357
     1358            $user = $order->get_user();
     1359
    13371360            // Add user role if defined in settings, and user's logged in
    1338             if($user && $this->set_customer_role != 'do_not_set_role') {
     1361            // Else, try to find a user account if setting is enabled
     1362            if($user) {
    13391363                $user->add_role($this->set_customer_role);
     1364            } else if($this->role_find_account == 'true') {
     1365                $user = get_user_by('email', $order->get_billing_email());
     1366
     1367                if($user) {
     1368                    if($order->get_billing_first_name() == $user->billing_first_name &&
     1369                    $order->get_billing_last_name() == $user->billing_last_name &&
     1370                    $order->get_billing_address_1() == $user->billing_address_1 &&
     1371                    $order->get_billing_city() == $user->billing_city &&
     1372                    $order->get_billing_state() == $user->billing_state &&
     1373                    $order->get_billing_postcode() == $user->billing_postcode &&
     1374                    $order->get_billing_country() == $user->billing_country) {
     1375                        $user->add_role($this->set_customer_role);
     1376                    }
     1377                }
    13401378            }
    13411379        }
     
    14021440            $uuid = $body['uuid'];
    14031441
     1442            $status = $body['status'];
     1443
    14041444            $order->update_meta_data('AgeChecker Status', $this->get_status_wording($body) );
    14051445
     
    14101450            $order->save();
    14111451
    1412             $this->set_verified_role($order->get_user());
     1452            if(isset($status) && $status == "accepted") {
     1453                $this->set_verified_role($order);
     1454            }
    14131455        }
    14141456
  • agecheckernet/trunk/readme.txt

    r2628388 r2636643  
    44Requires at least: 4.4
    55Tested up to: 5.8
    6 Stable tag: 1.7.2
     6Stable tag: 1.7.3
    77
    88AgeChecker.Net seamlessly and securely verifies the age of your customers directly on your website during the checkout process.
     
    6262
    6363== Changelog ==
     64
     65= 1.7.3 =
     66*Release Date - 29 November 2021*
     67
     68* Set customer role (if set) to newly created accounts made through guest orders.
     69* Give option to assign roles to existing accounts based on email and billing info from guest order.
    6470
    6571= 1.7.2 =
Note: See TracChangeset for help on using the changeset viewer.