businessdad icon

BE Table Rates Shipping - Empty Shipping Zones bug

businessdad | PRO | 05/01/15 05:10:06 PM UTC | 0 ⭐ | 1120 👁️ | Never ⏰ | []
PHP |

1.84 KB

|

None

|

0 👍

/

0 👎

// ORIGINAL CODE
class Zone_List_Table extends WP_List_Table {
 
    function __construct(){
        global $status, $page;
                
        //Set parent defaults
        parent::__construct( array(
            'singular'  => 'zone', 
            'plural'    => 'zones',
            'ajax'      => false
        ) );
        
        $this->shipping_zones = get_option( 'be_woocommerce_shipping_zones' );
        /* ISSUE
         * In some circumstances, at this point $this->shipping_zones is NULL,
         * even if get_option() returns a value. I ran extensive tests, in
         * some cases the following statement 
         * var_dump(
         *   get_option( 'be_woocommerce_shipping_zones' ),
         *   $this->shipping_zones
         * )
         *
         * returns an array, followed by NULL, when the two values should instead
         * match.
         *
         * POSSIBLE CAUSES
         * I could not find the exact cause of the issue, but it seems to have
         * something to do with the WP_List_Table__set() and __get() magic
         * methods. Since property $shipping_zones does not exist, the magic
         * methods are fired and return incorrect values.
         *
         * SOLUTION
         * Declare the $shipping_zones property explicitly (see below).
         */
    }
 
// FIXED CODE
class Zone_List_Table extends WP_List_Table {
    // @var array An array containing the shipping zones
    public $shipping_zones;    
    
    function __construct(){
        global $status, $page;
                
        //Set parent defaults
        parent::__construct( array(
            'singular'  => 'zone', 
            'plural'    => 'zones',
            'ajax'      => false
        ) );
        
        $this->shipping_zones = get_option( 'be_woocommerce_shipping_zones' );
    }

Comments