• Resolved Dmitry_Demir

    (@dmitry_demir)


    Hi,

    First of all, thank you for this easy-to-setup plugin, it’s almost exactly what I need for my custom website. However I need to change a few things.

    Is there a way to change the HTML of this plugin for the front-end without editing the plugin itself? Basically I need to change the contents of products_per_page_dropdown() function of WPPP_Front_End class. For example, I need the option name “products per page” outside of the select box. Also I would like to change the order in which the form is hooked into woocommerce_before_shop_loop (to customize where exactly this form is outputted). So I tried to first remove the function from the hook, but it didn’t work. Here’s the code I tried:

    add_action('woocommerce_before_shop_loop', 'remove_page_dropdown');
    function remove_page_dropdown() {
    	remove_action('woocommerce_before_shop_loop', array('WPPP_Front_End', 'products_per_page_dropdown'), 30);
    }

    I’ve also tried without the class:

    add_action('woocommerce_before_shop_loop', 'remove_page_dropdown');
    function remove_page_dropdown() {
    	remove_action('woocommerce_before_shop_loop', 'products_per_page_dropdown', 30);
    }

    But no result. Am I doing something wrong or changing the plugin’s source is the only way to do this?

    • This topic was modified 8 years, 6 months ago by Dmitry_Demir.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Dmitry_Demir

    (@dmitry_demir)

    As for changing the HTML, I thought of making a new class that would extend WPPP_Front_End and overwrite the products_per_page_dropdown function the way I need it, then I’d hook it instead of the default. But I’m not sure if that’d actually work.

    Plugin Author Jeroen Sormani

    (@sormano)

    Hi,

    Sorry for not hearing from me before, I sometimes don’t get notifications of the support threads ??

    To remove the hook: (untested)

    
    add_action('woocommerce_before_shop_loop', 'remove_page_dropdown');
    function remove_page_dropdown() {
    	remove_action('woocommerce_before_shop_loop', array( Woocommerce_Products_Per_Page()->fronte_end, 'products_per_page_dropdown'), 30);
    }
    

    You don’t need to extend the class per se, you can just use a function and add your own HTML there.
    Also note that there are certain action hooks in place that allow you to add additional parts (HTML) to the plugin.

    Hope that helps ??

    Cheers,
    Jeroen

    Thread Starter Dmitry_Demir

    (@dmitry_demir)

    Hi, Jeroen!

    Thanks a lot for showing me the right direction ?? There is a typo in your example in fronte_end and it doesn’t work with priority 30 (I’m a bit puzzled with why though), but it works with priority 25 (same as the hook was added in the plugin). So here’s what I ended up with:

    add_action('woocommerce_before_shop_loop', 'remove_page_dropdown');
    function remove_page_dropdown() {
    	remove_action('woocommerce_before_shop_loop', array( Woocommerce_Products_Per_Page()->front_end, 'products_per_page_dropdown'), 25);
    }

    Now I copied products_per_page_dropdown function to my function’s php and added it after removing the original one, it works like a charm with just one change – I had to replace $this with Woocommerce_Products_Per_Page()->front_end. That’s kind of a side note if someone is going to do the same and comes across this thread.

    Thanks again for helping out and good luck with further development!

    Plugin Author Jeroen Sormani

    (@sormano)

    Hi Dmitri,

    The priority 25 is required because it needs to be the same as the priority which is set to the ‘add_action’.

    I did notice that, but must’ve missed it when changing the code..

    Have a great day!
    Jeroen Sormani

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Changing HTML’ is closed to new replies.