Plugin Directory


Ignore:
Timestamp:
09/21/2026 08:05:18 AM (4 weeks ago)
Author:
retainful
Message:

v1.0.10 release

File:
1 edited

Legend:

Unmodified
Added
Removed
  • retainful/trunk/App/Controllers/Webhook.php

    r3655829 r3705113  
    916916                                        Customer::setCustomerEmail( $email );
    917917                                }
    918                                
     918                        }
     919
     920                        // Sync billing/shipping address fields (country, state, etc.)
     921                        // into WC()->customer, the session object every
     922                        // Customer::getCartCountry()/getCartState() read relies on.
     923                        // Runs on every tracking request (not nested inside the
     924                        // empty($email) block above) — WC()->checkout->get_value()
     925                        // resolves $email from $_POST on every request after the
     926                        // first one, which would otherwise skip this entirely, and
     927                        // address changes, from the second sync onward.
     928                        if ( $ajax_action === 'rnoc_track_user_data' ) {
     929                                $address_synced = false;
     930
     931                                // If no real shipping text was posted (Block Checkout, or
     932                                // Classic with "ship to a different address" unchecked),
     933                                // overwrite shipping with the current billing value —
     934                                // mirrors wc_ship_to_billing_address_only(), which the
     935                                // Store API has no equivalent for. Must actively
     936                                // overwrite, not just fall back when empty: <select>
     937                                // fields (country, state) never read as empty even when
     938                                // unused, so a stale value would otherwise stick.
     939                                $shipping_text_posted = Input::get( 'shipping_first_name', '' ) !== '' || Input::get( 'shipping_address_1', '' ) !== '';
     940
     941                                foreach ( Customer::getAddressFields() as $field ) {
     942                                        $billing_value = Input::get( 'billing_' . $field, '' );
     943                                        if ( $billing_value !== '' && Customer::setCustomerData( 'billing_' . $field, $billing_value ) ) {
     944                                                $address_synced = true;
     945                                        }
     946
     947                                        $shipping_value = $shipping_text_posted
     948                                                ? Input::get( 'shipping_' . $field, '' )
     949                                                : Customer::getCustomerData( 'billing_' . $field );
     950                                        if ( $shipping_value !== '' && Customer::setCustomerData( 'shipping_' . $field, $shipping_value ) ) {
     951                                                $address_synced = true;
     952                                        }
     953                                }
     954                                if ( $address_synced && Util::isMethodExists( WC()->customer, 'save' ) ) {
     955                                        WC()->customer->save();
     956                                }
     957
    919958                        }
    920959
Note: See TracChangeset for help on using the changeset viewer.