Advertisement
businessdad

BE Table Rates Shipping - Empty Shipping Zones bug

May 1st, 2015
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. // ORIGINAL CODE
  2. class Zone_List_Table extends WP_List_Table {
  3.  
  4.     function __construct(){
  5.         global $status, $page;
  6.                
  7.         //Set parent defaults
  8.         parent::__construct( array(
  9.             'singular'  => 'zone',
  10.             'plural'    => 'zones',
  11.             'ajax'      => false
  12.         ) );
  13.        
  14.         $this->shipping_zones = get_option( 'be_woocommerce_shipping_zones' );
  15.         /* ISSUE
  16.          * In some circumstances, at this point $this->shipping_zones is NULL,
  17.          * even if get_option() returns a value. I ran extensive tests, in
  18.          * some cases the following statement
  19.          * var_dump(
  20.          *   get_option( 'be_woocommerce_shipping_zones' ),
  21.          *   $this->shipping_zones
  22.          * )
  23.          *
  24.          * returns an array, followed by NULL, when the two values should instead
  25.          * match.
  26.          *
  27.          * POSSIBLE CAUSES
  28.          * I could not find the exact cause of the issue, but it seems to have
  29.          * something to do with the WP_List_Table__set() and __get() magic
  30.          * methods. Since property $shipping_zones does not exist, the magic
  31.          * methods are fired and return incorrect values.
  32.          *
  33.          * SOLUTION
  34.          * Declare the $shipping_zones property explicitly (see below).
  35.          */
  36.     }
  37.  
  38. // FIXED CODE
  39. class Zone_List_Table extends WP_List_Table {
  40.     // @var array An array containing the shipping zones
  41.     public $shipping_zones;    
  42.    
  43.     function __construct(){
  44.         global $status, $page;
  45.                
  46.         //Set parent defaults
  47.         parent::__construct( array(
  48.             'singular'  => 'zone',
  49.             'plural'    => 'zones',
  50.             'ajax'      => false
  51.         ) );
  52.        
  53.         $this->shipping_zones = get_option( 'be_woocommerce_shipping_zones' );
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement