Customise the WooCommerce Product Widget

I need to redirect the user to a specific page by placing a hyperlink just before a closing </ul> tag (which is within a WordPress sidebar widget).

An example of what I am trying to achieve can be found below, using the WooCommerce Products widget which has been slightly modified to include an additional Specials hyperlink:

Read More

enter image description here


I am using the WooCommerce 2.9.1 plugin, and believe that the file I need to modify is the
class-widgets-products.php file. This file is made up with the following code – http://pastebin.com/vgpSqa6X.


On line 178 I have placed the following, which will display a hyperlink taking the user to a Specials page on the website:

echo '<a href="'. get_site_url().'/specials/" class="go-to">» Specials</a>';

However, with this particular widget, it creates three separate instances and this will apply the hyperlink to All Products, Featured Products and On-sale Products.

enter image description here


How can I create separate hyperlinks that will apply to the widget, depending on which option has been selected in the admin menu?

For example, if the Featured Products option has been selected, it will output a Featured Products hyperlink at the bottom, and if the On-sale option has been selected, it will output a Specials hyperlink at the bottom.

Thank you.

Related posts

Leave a Reply

1 comment

  1. The answer seems to lie in :

    $this->settings->show->options
    

    or :

    $this->settings['show']['options']
    

    …as the code you have pasted suggests.

    Just evaluate this value with if’s (or switches, whatever you feel comfortable with) :

    if ($this->settings['show']['options'] == "this_particular_kind")
    {
       $link_at_the_bottom = '<a href="'. get_site_url().'/this_particular_kind/" class="go-to">» This Particular Kind</a>';
    }
    ...