Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // my plugin mimics the setup_product_data function
- function setup_product_data( $post ) {
- if ( is_int( $post ) ) $post = get_post( $post );
- if ( $post->post_type !== 'product' ) return;
- unset( $GLOBALS['product'] );
- $GLOBALS['product'] = new WC_Product_Suggested_Donation( $post->ID );
- return $GLOBALS['product'];
- }
- //versus creating a new global object
- function setup_product_data( $post ) {
- if ( is_int( $post ) ) $post = get_post( $post );
- if ( $post->post_type !== 'product' ) return;
- unset( $GLOBALS['donation_product'] );
- $GLOBALS['donation_product'] = new WC_Product_Suggested_Donation( $post->ID );
- return $GLOBALS['donation_product'];
- }
- //where
- class WC_Product_Suggested_Donation extends WC_Product {
- static $suggested_donation = false;
- static $suggested_donation_singular = false;
- static $open_range = false;
- static $close_range = false;
- function __construct( $id ) {
- //reinitialize parent
- //is it efficient to do this? needed if i unset $GLOBALS['product'],
- //but not if i create my own global
- parent::__construct($id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement