Plugin Directory

Changeset 3229725


Ignore:
Timestamp:
01/27/2025 03:43:23 PM (14 months ago)
Author:
masterhomepage
Message:

fixed endless reload on checkout page

Location:
riskcube-von-creditreform-schweiz/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • riskcube-von-creditreform-schweiz/trunk/assets/riskcube.front.js

    r3071289 r3229725  
    33        console.error('riskCubeCf object not present')
    44    }
     5    //require('riskcube.legacy.js');
     6    window.setTimeout(function() {
     7        var requiredFields = jQuery('#billing_first_name, #billing_last_name, #billing_address_1, #billing_postcode, #billing_city, #billing_phone, #billing_email');
     8        var shippingToggle = jQuery('#ship-to-different-address-checkbox');
     9        var shippingFields = jQuery('#shipping_first_name, #shipping_last_name, #shipping_address_1, #shipping_postcode, #shipping_city');
     10        jQuery("#billing_first_name_field, #billing_last_name_field, #billing_company_field, #billing_email").addClass("address-field");
    511
    6     require('riskcube.legacy.js');
     12        jQuery(requiredFields).off('change').on('change', executeCall);
     13        jQuery(shippingFields).off('change').on('change', executeCall);
     14
     15        function executeCall() {
     16            var emptyFields, fields;
     17
     18            fields = jQuery(requiredFields);
     19
     20            if (jQuery(shippingToggle).is(':checked')) {
     21                fields = fields.add(jQuery(shippingFields));
     22            }
     23            emptyFields = jQuery(fields).filter(function () {
     24                return jQuery(this).val() === "";
     25            });
     26            console.log(emptyFields);
     27
     28            if (emptyFields.length <= 1) {
     29                jQuery(document.body).trigger('update_checkout');
     30            }
     31        }
     32    }, 1000);
    733    if (typeof wc === 'object') {
    834        require('riskcube.blocks.js');
  • riskcube-von-creditreform-schweiz/trunk/readme.txt

    r3224301 r3229725  
    55Tested up to: 6.7.1
    66Requires PHP: 7.4
    7 Stable Tag: 2.4.12.9
     7Stable Tag: 2.4.12.10
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    145145== Changelog ==
    146146
     147= 2.4.12.10 =
     148**Bug Fixes**
     149- Fixed endless reload on checkout page
     150
    147151= 2.4.12.9 =
    148152**Bug Fixes**
  • riskcube-von-creditreform-schweiz/trunk/riskcube.php

    r3224301 r3229725  
    66 * Plugin Name: RiskCUBE von Creditreform Schweiz
    77 * Plugin URI:
    8  * Version: 2.4.12.9
     8 * Version: 2.4.12.10
    99 * Description: RiskCube
    1010 * Author: Masterhomepage GmbH
  • riskcube-von-creditreform-schweiz/trunk/src/Core/RiskCube.php

    r3224301 r3229725  
    5252                //    // add_action('woocommerce_checkout_create_order', [__CLASS__, 'before_checkout_create_order'], 20, 2);
    5353                //}
    54 
    5554                if(self::$isClassicCheckout) {
    5655                    add_filter('woocommerce_available_payment_gateways', [__CLASS__, 'controlPaymentGateways'], 10, 1);
     
    6261                add_action('wp_head', [__CLASS__, 'new_checkout_header']);
    6362            }
    64 
    6563            // Frontend Assets
    6664            foreach ($jsFiles as $jsFile) {
    6765                wp_enqueue_script(basename($jsFile), RISKCUBE__PLUGIN_URL . $jsFile, [], FileHelper::get_file_version($jsFile), true);
    6866            }
     67         
    6968
    7069            if (get_option('wc_riskcube_invoice_payment_gateway', 0) == 1) {
     
    214213    public static function woocommerce_checkout_update_order_review($post_data)
    215214    {
    216         if (!empty($post_data)) {
    217             parse_str($post_data, $data);
    218         } else {
    219             return false;
    220         }
    221 
    222         WC()->customer->set_props([
    223             'billing_first_name' => isset($data['billing_first_name']) ? wp_unslash($data['billing_first_name']) : null,
    224             'billing_last_name' => isset($data['billing_last_name']) ? wp_unslash($data['billing_last_name']) : null,
    225             'billing_company' => isset($data['billing_company']) ? wp_unslash($data['billing_company']) : null,
    226             'billing_phone' => isset($data['billing_phone']) ? wp_unslash($data['billing_phone']) : null,
    227             'billing_email' => isset($data['billing_email']) ? wp_unslash($data['billing_email']) : null,
    228         ]);
    229 
    230         if (wc_ship_to_billing_address_only()) {
    231             WC()->customer->set_props([
    232                 'shipping_first_name' => isset($data['billing_first_name']) ? wp_unslash($data['billing_first_name']) : null,
    233                 'shipping_last_name' => isset($data['billing_last_name']) ? wp_unslash($data['billing_last_name']) : null,
    234                 'shipping_company' => isset($data['billing_company']) ? wp_unslash($data['billing_company']) : null,
    235                 'shipping_phone' => isset($data['billing_phone']) ? wp_unslash($data['billing_phone']) : null,
    236                 'shipping_email' => isset($data['billing_email']) ? wp_unslash($data['billing_email']) : null,
    237             ]);
    238         } else {
    239             WC()->customer->set_props([
    240                 'shipping_first_name' => isset($data['shipping_first_name']) ? wp_unslash($data['shipping_first_name']) : null,
    241                 'shipping_last_name' => isset($data['shipping_last_name']) ? wp_unslash($data['shipping_last_name']) : null,
    242                 'shipping_company' => isset($data['shipping_company']) ? wp_unslash($data['shipping_company']) : null,
    243                 'shipping_phone' => isset($data['shipping_phone']) ? wp_unslash($data['billing_phone']) : null,
    244                 'shipping_email' => isset($data['shipping_email']) ? wp_unslash($data['shipping_email']) : null,
    245             ]);
    246         }
    247 
    248         // cancel the shipping address that woocommerce tries to set if the checkbox is not marked
    249         if (array_key_exists('ship_to_different_address', $data) && !$data['ship_to_different_address']) {
    250             WC()->customer->set_props([
    251                 'shipping_first_name' => '',
    252                 'shipping_last_name' => '',
    253                 'shipping_company' => '',
    254                 'shipping_phone' => '',
    255                 'shipping_email' => '',
    256 
    257                 'shipping_country' => '',
    258                 'shipping_state' => '',
    259                 'shipping_postcode' => '',
    260                 'shipping_city' => '',
    261                 'shipping_address_1' => '',
    262                 'shipping_address_2' => '',
    263             ]);
    264             WC()->customer->save();
    265 
     215       /*
    266216            // 20220304 disabled, was breaking tax/shipping calculation
    267217            //foreach (['s_country', 's_state', 's_postcode', 's_city', 's_address', 's_address_2'] as $field) {
    268218            //unset($_POST[$field]);
    269219            //}
     220        }*/
     221        if( empty($post_data) ) return false;
     222        parse_str($post_data, $data);
     223
     224        // Unslash the input data
     225        $data = wp_unslash( $data );
     226
     227        $ship_to_different_address = isset($data['ship_to_different_address']) ? wc_string_to_bool($data['ship_to_different_address']) : false;
     228
     229        $customer_fields = ['first_name', 'last_name', 'company', 'phone', 'email'];
     230        foreach ($customer_fields as $field) {
     231            $billing_field = 'billing_' . $field;
     232            $shipping_field = 'shipping_' . $field;
     233            $value = isset( $data[$billing_field] ) ? $data[$billing_field] : null;
     234            $value = strpos($field,'email') !== false ? sanitize_email($value) : sanitize_text_field($value);
     235            if( WC()->customer->{"get_{$billing_field}"}() !== $value ) {
     236                WC()->customer->{"set_{$billing_field}"}($value);
     237            }
     238            /* There is no get / set shipping_email */
     239            if( $field !== 'email' && $ship_to_different_address ){
     240                $value = isset( $data[$shipping_field] ) ? sanitize_text_field( $data[$shipping_field] ) : null;
     241                if( WC()->customer->{"get_{$shipping_field}"}() !== $value ) {
     242                    WC()->customer->{"set_{$shipping_field}"}($value);
     243                }
     244            }
     245        }
     246        //cancel the shipping address if the checkbox is not checked
     247        if (!$ship_to_different_address) {
     248            WC()->customer->set_props([
     249                'shipping_first_name' => '',
     250                'shipping_last_name'  => '',
     251                'shipping_company'    => '',
     252                'shipping_phone'      => '',
     253                'shipping_email'      => '',
     254                'shipping_country'    => '',
     255                'shipping_state'      => '',
     256                'shipping_postcode'   => '',
     257                'shipping_city'       => '',
     258                'shipping_address_1'  => '',
     259                'shipping_address_2'  => '',
     260            ]);
     261            // Save changes to customer
     262            WC()->customer->save();
    270263        }
    271264    }
Note: See TracChangeset for help on using the changeset viewer.