• 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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Sirion89

    (@sirion89)

    Update: that edit is not complete, since it actually breaks backend ajax request like updating prices inside product edit.

    We would need to find something more flexible

    Plugin Author Varun Sridharan

    (@varunms)

    @sirion89
    Hi There
    Sorry about the delayed response.
    As of now with this version of Role Based Price we do not support Ajax by default.

    but we are enabling ajax option by default in a upcoming brand new version of this plugin ??

    Plugin Author Varun Sridharan

    (@varunms)

    @sirion89 if you still need to get role based pricing in ajax then you need to do a small work around. by adding the below code

    
    add_action("wp_ajax_{$action}" ,"your_prefix_enable_wcrbp",-10);
    
    function your_prefix_enable_wcrbp(){
    new WooCommerce_Role_Based_Price_Product_Pricing(true);
    }
    

    Note For this to work you need to find the ajax action slug and replace it with $action in add_action function above.

    Thread Starter Sirion89

    (@sirion89)

    Hello Varun,

    Thank you for the quick response, yeah i thought about that solution too but there are multiple ajax request, i don’t really know if it’s worth searching for all of them ahahahah

    I will look forward for the next update ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Role based price not working in ajax’ is closed to new replies.