douhao2856 2014-05-27 10:33
浏览 97
已采纳

自定义WooCommerce产品小部件

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:

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">&#187; 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.

  • 写回答

1条回答 默认 最新

  • dtudj42064 2014-05-27 10:46
    关注

    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">&#187; This Particular Kind</a>';
    }
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟