Advertisement
helgatheviki

reinitializing parent class WC_Product

Jul 20th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. // my plugin mimics the setup_product_data function
  2.  
  3.  function setup_product_data( $post ) {
  4.     if ( is_int( $post ) ) $post = get_post( $post );
  5.     if ( $post->post_type !== 'product' ) return;
  6.     unset( $GLOBALS['product'] );
  7.     $GLOBALS['product'] = new WC_Product_Suggested_Donation( $post->ID );
  8.     return $GLOBALS['product'];
  9.   }
  10.  
  11. //versus creating a new global object
  12.  
  13.   function setup_product_data( $post ) {
  14.     if ( is_int( $post ) ) $post = get_post( $post );
  15.     if ( $post->post_type !== 'product' ) return;
  16.     unset( $GLOBALS['donation_product'] );
  17.     $GLOBALS['donation_product'] = new WC_Product_Suggested_Donation( $post->ID );
  18.     return $GLOBALS['donation_product'];
  19.   }
  20.  
  21.  
  22. //where
  23.  
  24. class WC_Product_Suggested_Donation extends WC_Product {
  25.    
  26.     static $suggested_donation = false;
  27.     static $suggested_donation_singular = false;
  28.     static $open_range = false;
  29.     static $close_range = false;
  30.  
  31.     function __construct( $id ) {
  32.    
  33.         //reinitialize parent    
  34.         //is it efficient to do this? needed if i unset $GLOBALS['product'],
  35.         //but not if i create my own global
  36.         parent::__construct($id);
  37.          }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement