Plugin Directory

Changeset 3048580


Ignore:
Timestamp:
03/10/2024 12:19:03 PM (2 years ago)
Author:
oscomsupport
Message:

Fixed Session issue, updated to work with WC session.

Location:
agreeme-checkboxes-for-woocommerce
Files:
28 added
3 edited

Legend:

Unmodified
Added
Removed
  • agreeme-checkboxes-for-woocommerce/trunk/inc/classes/agrwc-compatibility.php

    r2996245 r3048580  
    4040    $val_arr[1]=AGRWC_YES;
    4141       
    42                     if ( ! session_id() ) {
    43         session_start();
    44     }
     42
    4543            $cbxs   = AGRWC_CBX::get_cbxs();
    4644        $show_cbx=array();
     
    7876        if(in_array(trim($keysarr[1]),$show_cbx))
    7977        {
     78           
     79            $id=(int)trim($keysarr[1]);
     80            $valid=WC()->session->get( 'agrwc-'.$id );
    8081            $meta_key='Agree-'.$id;
    81 $meta_value=$cbx->get_label()."-".$val_arr[$_SESSION['agrwc'][$id]];
     82$meta_value=$cbx->get_label()."-".$val_arr[(int)$valid];
    8283    $order->{$meta_key} = $meta_value;
    8384                   
     
    105106       
    106107        if(in_array(trim($keysarr[1]),$show_cbx))
    107         {
     108        {$id=(int)trim($keysarr[1]);
     109           
    108110            $meta_key='Agree-'.$id;
    109 $meta_value=$cbx->get_label()."-".$val_arr[$_SESSION['agrwc'][$id]];
     111            $valid=WC()->session->get( 'agrwc-'.$id );
     112$meta_value=$cbx->get_label()."-".$val_arr[$valid];
    110113    $order->{$meta_key} = $meta_value;
    111114                   
     
    120123}           
    121124                       
    122        
    123        
     125    /////////////   
     126    if($session_started==1) session_write_close();
    124127   
    125128        return $order;
  • agreeme-checkboxes-for-woocommerce/trunk/inc/classes/agrwc-frontend.php

    r3001295 r3048580  
    2525            $enabled = get_option('agrwc_enabled');
    2626            if (!$enabled || $enabled == "no") return false;
    27             if (session_status() == PHP_SESSION_NONE) {
    28    
    29        
    30    
    31         session_start();
    32     }
     27   
    3328
    3429           
     
    4035            $this->checkoutpage_locations['after_terms_conditions']='woocommerce_checkout_after_terms_conditions';
    4136            $this->checkoutpage_locations['before_submit']='woocommerce_review_order_before_submit';
    42            
     37        //  add_action( 'init',  array($this, 'xxxxxxxxxx_init_session'), PHP_INT_MAX);
    4338           
    4439            add_action('woocommerce_before_add_to_cart_button', array($this, 'addto_product_page'), PHP_INT_MAX);
     
    5247            add_action('woocommerce_checkout_before_terms_conditions', array($this, 'addto_checkout_page'), PHP_INT_MAX);
    5348            add_action('woocommerce_checkout_after_terms_conditions', array($this, 'addto_checkout_page'), PHP_INT_MAX);
    54             add_action('woocommerce_review_order_before_submit', array($this, 'addto_checkout_page'), PHP_INT_MAX);
    55                                                
    56        add_action('woocommerce_thankyou', array($this, 'order_completed'), PHP_INT_MAX);
    57     add_action('woocommerce_checkout_update_order_meta', array($this, 'update_agree_checkbox_fields_order_meta'));
     49            add_action('woocommerce_review_order_before_submit', array($this, 'addto_checkout_page'), PHP_INT_MAX);                                 
     50            add_action('woocommerce_thankyou', array($this, 'order_completed'), PHP_INT_MAX);
     51            add_action('woocommerce_checkout_update_order_meta', array($this, 'update_agree_checkbox_fields_order_meta'));
    5852            add_action('woocommerce_cart_calculate_fees', array($this, 'add_fees'), PHP_INT_MAX);
    5953            add_action('admin_enqueue_scripts', array($this, 'admin_enqueue'), PHP_INT_MAX);   
     
    6963   
    7064        }
    71        
    72            
     65
     66
    7367        public function admin_enqueue($hook) {
    7468            // Only add to the edit.php admin page.
     
    9286         */
    9387        public function order_completed($order_id) {
    94    
    95             if(isset($_SESSION['agrwc']))
    96             {
    97             $_SESSION['agrwc'] = '';
    98             unset($_SESSION['agrwc']);
    99             }
     88            $cbxs = AGRWC_CBX::get_cbxs();
     89    foreach ($cbxs as $id => $cbx) {
     90        WC()->session->__unset( 'agrwc-'.$id );
     91       
     92    }
    10093        }
    10194        public function agrwc_post() {
     
    10598                //loop through all...
    10699                foreach ($cbxs as $id => $cbx) {
    107                     if (isset($_POST[$id])) unset($_SESSION['agrwc'][$id]);
    108                     if ($_POST[$id]) {
    109                         $_SESSION['agrwc'][$id] = (int)$_POST[$id]; //checkbox if checked should be 1
     100                    if (isset($_POST[$id])) WC()->session->__unset( 'agrwc-'.$id );
     101                    if (isset($_POST[$id]) && $_POST[$id]) {
     102                        WC()->session->set('agrwc-'.$id,(int)$_REQUEST[$id]);
     103                       // $_SESSION['agrwc'][$id] = (int)$_POST[$id]; //checkbox if checked should be 1
    110104                    }
    111105                }
     
    171165                        $passed = false;
    172166                    }
    173                     $_SESSION['agrwc'][$id] = (int)$_REQUEST[$id]; //store in session.
     167                    WC()->session->set('agrwc-'.$id,(int)$_REQUEST[$id]);
     168                  //  $_SESSION['agrwc'][$id] = (int)$_REQUEST[$id]; //store in session.
    174169                   
    175170                }
     
    215210                    $match_product = false;
    216211                    if (is_array($l_products) && count($l_products)) {
     212                       
     213                   
     214                       
    217215                        if (in_array($_REQUEST['add-to-cart'], $l_products)) {
    218216                            if (($cbx->get_required() == 'yes') && !isset($_REQUEST[$id])) {
    219217                                //wc_add_notice( __( 'Some required fields are missing', 'woocommerce' ), 'error' );
    220                                
    221                             }
    222                         }
    223                     }
    224                     if (isset($_REQUEST[$id]) && $_REQUEST['add-to-cart']) $_SESSION['agrwc'][$id] = (int)$_REQUEST[$id]; //store in session.
     218                               $passed = false; 
     219                            }
     220                        }
     221                    }
     222                    if (isset($_REQUEST[$id]) && $_REQUEST['add-to-cart']) {
     223                    WC()->session->set('agrwc-'.$id,(int)$_REQUEST[$id]);
     224                    //$_SESSION['agrwc'][$id] = (int)$_REQUEST[$id]; //store in session.
     225                   
     226                   
     227                    }
    225228                   
    226229                }
     
    258261                    if (is_array($l_products) && count($l_products)) {
    259262                        if (in_array($product_id, $l_products)) {
    260                        
    261                       if(isset($_SESSION['agrwc'][$id]))  unset($_SESSION['agrwc'][$id]);
     263                                WC()->session->__unset( 'agrwc-'.$id );
     264                     // if(isset($_SESSION['agrwc'][$id]))  unset($_SESSION['agrwc'][$id]);
    262265                        }
    263266                    }
     
    316319                        $reqclass = '';
    317320                    };
    318                     if (isset($_SESSION[$id])) $checked = 1;
     321                   
     322                    if (WC()->session->get( 'agrwc-'.$id ))$checked = 1;
     323                   // if (isset($_SESSION[$id])) $checked = 1;
    319324                    else $checked = 0;
    320325                    if ($match_product) {
     
    388393                                $reqclass = '';
    389394                            };
    390                             if (isset($_SESSION['agrwc'][$id])) $checked = 1;
    391                             else $checked = 0;
     395                            if (WC()->session->get( 'agrwc-'.$id ))$checked = 1;
     396                   // if (isset($_SESSION[$id])) $checked = 1;
     397                    else $checked = 0;
    392398                            woocommerce_form_field($id, array('type' => 'checkbox', 'class' => array('form-row privacy', $reqclass), 'label_class' => array('woocommerce-form__label checkbox'), 'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox agrwc-cbx', $reqclass), 'required' => $req, 'label' => $cbx->get_label(),), $checked);
    393399                            $this->sdata[$id] = esc_js($cbx->get_reqalert());
    394400                        }else
    395401                        {
    396                     if(isset($_SESSION['agrwc'][$id]))  unset($_SESSION['agrwc'][$id]);
     402                    if (WC()->session->get( 'agrwc-'.$id )) WC()->session->__unset( 'agrwc-'.$id );
    397403                           
    398404                        }
     
    400406                    {
    401407                       
    402                         if(isset($_SESSION['agrwc'][$id]))  unset($_SESSION['agrwc'][$id]);
     408                        if (WC()->session->get( 'agrwc-'.$id )) WC()->session->__unset( 'agrwc-'.$id );
    403409                   
    404410                    }
     
    494500                                $reqclass = '';
    495501                            };
    496                             if (isset($_SESSION['agrwc'][$id])) $checked = 1;
    497                             else $checked = 0;
     502                                if (WC()->session->get( 'agrwc-'.$id ))$checked = 1;
     503                    else $checked = 0;
    498504                       
    499505                       
     
    525531                $location_arr = $cbx->get_locations();
    526532                $fee_value = $cbx->get_add_fee();
    527                 if ((in_array(3, $location_arr) || in_array(1, $location_arr) || in_array(2, $location_arr)) && $fee_value && isset($_SESSION['agrwc'][$id]) && $_SESSION['agrwc'][$id]) //add fee only works from checkout page..
     533                if ((in_array(3, $location_arr) || in_array(1, $location_arr) || in_array(2, $location_arr)) && $fee_value && WC()->session->get( 'agrwc-'.$id )) //add fee only works from checkout page..
    528534                {
    529535                   
     
    745751               
    746752                $ix++;
    747                 if (isset($_SESSION['agrwc'][$id])) {
    748                    
    749        
     753               
     754                $valid=WC()->session->get( 'agrwc-'.$id );
     755               
     756                if ($valid) {
     757                   
    750758
    751759
     
    759767                        //HPOS
    760768    $order_updated=1;
    761         $order->update_meta_data('_agrwc_' . $id, $cbx->get_label() . " - " . $val_arr[(int)$_SESSION['agrwc'][$id]] ); ///
     769   
     770   
     771        $order->update_meta_data('_agrwc_' . $id, $cbx->get_label() . " - " . $val_arr[$valid] ); ///
    762772
    763773
    764774                    }else
    765                     update_post_meta($order_id, '_agrwc_' . $id, $cbx->get_label() . " - " . $val_arr[(int)$_SESSION['agrwc'][$id]]);
     775                    update_post_meta($order_id, '_agrwc_' . $id, $cbx->get_label() . " - " . $val_arr[(int)$valid]);
    766776                }
    767777               
    768778            }
     779           
     780           
     781           
    769782            if($order_updated){"Order saved"; $order->save();
     783           
     784           
     785           
    770786            }
    771787       
    772788           
    773789            add_action('woocommerce_checkout_update_order_meta', array($this, 'update_agree_checkbox_fields_order_meta'));
     790       
     791   
    774792       
    775793       
  • agreeme-checkboxes-for-woocommerce/trunk/readme.txt

    r2996245 r3048580  
    33Tags: woocommerce, checkout, woo commerce
    44Requires at least: 5.0
    5 Tested up to: 6.4.1
    6 Stable tag: 1.1.0
     5Tested up to: 6.4.3
     6Stable tag: 1.1.1
    77License: GNU General Public License v3.0
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    5050
    5151== Changelog ==
     52= 1.0.1 =
     53Changed to native WC session
    5254
    5355= 1.0.3 =
Note: See TracChangeset for help on using the changeset viewer.