Role based price not working in ajax
-
Hello,
when i’m performing ajax request your plugin hooks doesn’t get loaded. The result is that if i try to get the product price while being on ajax request i get the standard price w/o considering your plugin’s product rules.Here is what i’ve found, inside the file: wp-content/plugins/woocommerce-role-based-price/bootstrap.php you’ve got:
/** * Inits loaded Class */ public function init() { do_action( 'wc_rbp_before_init' ); self::$functions = new WooCommerce_Role_Based_Price_Functions; self::$settings = new WooCommerce_Role_Based_Price_Settings_Framework; self::$shortcode_handler = new WooCommerce_Role_Based_Price_Shortcode_Handler; if ( wc_rbp_is_request( 'admin' ) ) { self::$admin = new WooCommerce_Role_Based_Price_Admin; } else { self::$frontend = new WooCommerce_Role_Based_Price_Product_Pricing; } do_action( 'wc_rbp_init' ); }
I think you should reconsider the if-else which loads frontend or admin hooks.
I think it would be better having it like this:if ( wc_rbp_is_request( 'frontend' ) ) { self::$frontend = new WooCommerce_Role_Based_Price_Product_Pricing; } else if ( wc_rbp_is_request( 'admin' ) ) { self::$admin = new WooCommerce_Role_Based_Price_Admin; }
Since if you are using ajax wp_admin is true, therefore u wouldn’t load frontend hooks which leads to incorrect prices.
Am i missing something? is there a reason behind your choice? Atm on my production website i had to edit your core file with what i’ve posted and it looks like working.
Cheers,
Diego
- The topic ‘Role based price not working in ajax’ is closed to new replies.