• Resolved rodricus

    (@rodricus)


    Hello I am using the Product Configurator plugin.

    I want to know through the functions.php if a current page is using the product configurator functionality. I noticed the body has a class named “is_configurable” at the front of my website, but I can’t retrieve it with get_body_class();

    So how can I know though functions.php if the product configurator is being used?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Marc Lacroix

    (@marcusig)

    Hi there,

    Technically, you should be able to use get_body_class , as is_configurable is added using the filter body_class.

    Otherwise you can use the function mkl_pc_is_configurable()

    For example

    if ( function_exists( 'mkl_pc_is_configurable' ) && mkl_pc_is_configurable() ) {
        // do something for configurable products... 
    }

    You can also pass the product ID to the function if needed.

    Marc

    Thread Starter rodricus

    (@rodricus)

    Hello Marc, thank you for your reply but unfortunately it’s not working.

    I need to have the hook which can be used and can check your plugin after your plugin is loaded. Do you know which hook that is?

    Plugin Contributor Marc Lacroix

    (@marcusig)

    You can try the hook mkl_pc_is_loaded

    E.g.

    add_action( 'mkl_pc_is_loaded', function() { 
    // your code 
    });

    alternatively, plugins_loaded should work as well, with a priority above 90.

    Marc

    Thread Starter rodricus

    (@rodricus)

    No nothing is working.

    Plugin Contributor Marc Lacroix

    (@marcusig)

    Can you share your code here, if possible in its context?

    Thread Starter rodricus

    (@rodricus)

    Hello Marc,

    I managed to make the code working, here’s the code:

    add_filter( 'woocommerce_get_price_html', 'add_text_before_product_price' );
    function add_text_before_product_price( $price ) {
    	if ( function_exists( 'mkl_pc_is_configurable' ) && mkl_pc_is_configurable() ) {
    		$text = __('From');
    		return $text . ' ' . $price;
    	}
    	else {
    		return $price;
    	}
    }

    I wanted to show the string “From” in front of the price if that product has a product configurator. It’s working now. Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Check if page uses product configurator’ is closed to new replies.