Changeset 3833112
- Timestamp:
- 11/29/2026 01:51:43 PM (less than one hour ago)
- Location:
- grafo-for-woocommerce/trunk
- Files:
-
- 2 edited
-
grafo-for-woocommerce.php (modified) (3 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
grafo-for-woocommerce/trunk/grafo-for-woocommerce.php
r3833092 r3833112 3 3 * Plugin Name: Grafo for WooCommerce 4 4 * Description: Creates WooCommerce orders and updates delivery addresses, with automatic shipping and fee calculation, from Grafo. 5 * Version: 1.1.2 15 * Version: 1.1.22 6 6 * Author: Grafo 7 7 * Author URI: https://www.grafoflow.com/ … … 137 137 } 138 138 139 /* Ensure WC()->session exists. Now that shipping rates are calculated 140 * through WooCommerce's own native WC_Shipping::calculate_shipping() 141 * pipeline (see below), that code path commonly caches calculated 142 * rates per package hash via WC()->session->get()/->set() -- and in 143 * a headless REST request there is no session cookie, so WC()->session 144 * is null here, causing "Call to a member function get() on null". 145 * This mock never actually caches anything (get() always returns the 146 * default, set() is a no-op), which just means rates are recalculated 147 * fresh on every request instead of being cached across requests -- 148 * exactly the right behavior for a stateless REST endpoint. */ 149 $had_session = !is_null(WC()->session); 150 if (!$had_session) { 151 WC()->session = new class { 152 public function get( $key, $default = null ) { return $default; } 153 public function set( $key, $value ) {} 154 public function __get( $key ) { return null; } 155 public function __set( $key, $value ) {} 156 public function __isset( $key ) { return false; } 157 public function __unset( $key ) {} 158 public function has_session() { return false; } 159 public function get_session_cookie() { return false; } 160 public function get_customer_id() { return 0; } 161 public function __call( $name, $args ) { return null; } 162 }; 163 } 164 139 165 /* WBS (Weight-Based Shipping) v5.0.9+ reads the cart from $package['cart'] 140 166 * rather than from WC()->cart ("User package passed to calculate_shipping() … … 191 217 if (!$had_customer) 192 218 WC()->customer = null; 219 if (!$had_session) 220 WC()->session = null; 193 221 194 222 } catch (Throwable $e) { -
grafo-for-woocommerce/trunk/readme.txt
r3833077 r3833112 7 7 WC requires at least: 7.0 8 8 WC tested up to: 11.1 9 Stable tag: 1.1.2 19 Stable tag: 1.1.22 10 10 License: GPLv2 or later 11 11 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 67 67 == Changelog == 68 68 69 = 1.1.22 = 70 * Fix: switching to WooCommerce's native calculate_shipping() pipeline in 1.1.21 surfaced a new "Call to a member function get() on null" fatal, the same class of error WC()->customer null caused earlier (1.1.x) - this time from WC()->session, which the native pipeline commonly reads/writes to cache calculated rates per package hash. A headless REST request has no session cookie so WC()->session is null here. Added a minimal mock (get() always returns the default, set() is a no-op) so rates are simply recalculated fresh on every request instead of relying on session-based caching, which is the correct behavior for a stateless REST endpoint anyway. 71 69 72 = 1.1.21 = 70 73 * Change: shipping rate lookup now goes through WooCommerce's own standard WC()->shipping()->calculate_shipping() pipeline again, instead of the hand-rolled zone-matching-plus-manual-global-method-instantiation loop added in 1.1.9. WBS Legacy's own get_instance_id() override returns -1 specifically to avoid being skipped by WC_Shipping::calculate_shipping_for_package() - it is written to work correctly through this exact native pipeline, including its own is_available() check being called the normal way. This removes all the plugin-specific hand-rolled special-casing that loop accumulated, while keeping every fix made to the mock cart/customer objects (1.1.13-1.1.18) and the $package['cart'] injection (1.1.15) that this pipeline still depends on. … … 143 146 == Upgrade Notice == 144 147 148 = 1.1.22 = 149 Fixes a fatal error ("Call to a member function get() on null") introduced by 1.1.21's switch to WooCommerce's native shipping pipeline, caused by WC()->session being null in a headless REST request. 150 145 151 = 1.1.21 = 146 152 Switches shipping rate lookup back to WooCommerce's own native calculation pipeline, which WBS Legacy's own code is specifically written to integrate with, removing the hand-rolled method-loop special-casing added since 1.1.9.
Note:
See TracChangeset
for help on using the changeset viewer.