【问题标题】:Removing product Link from the product price on content-product.php template从 content-product.php 模板的产品价格中删除产品链接
【发布时间】:2016-07-11 15:15:49
【问题描述】:

我正在使用 Woocommerce WP 插件。在我的商店页面上,我想从<span class="price"> 中删除指向产品页面的链接<a>

this 文章中,作者建议更改 /your-child-theme/woocommerce/content-product.php WooCommerce 模板中的标签,但这在最新版本中不再可行WooCommerce 版本 2.6+。

我只找到了删除整个链接的方法,而不仅仅是价格链接。

我怎样才能只从价格中移动链接?

这就是我想要的:

<a href="www.link-to-single-product.com">
    <h3>TITLE</h3>
    <img width="300" height="200" src="www.link.com">

</a> <!-- <===== TO HERE -->

    <span class="price">
        <span class="amount">PRICE</span>
    </span>

</a> <!-- Moving this close tag FROM HERE -->

【问题讨论】:

    标签: php wordpress templates woocommerce product


    【解决方案1】:

    Update2(代码中缺少2个“;”,这是500错误。所以你应该重试。

    这是 content-product.php 模板的摘录(带有解决方案(1)和(2):

    /**
     * woocommerce_after_shop_loop_item_title hook.
     *
     * @hooked woocommerce_template_loop_rating - 5
     * <===  <===  <===  <===  <===  <===  <===  <===  <=== (2) To here
     * @hooked woocommerce_template_loop_price - 10  ====> (1) From here
     */
    do_action( 'woocommerce_after_shop_loop_item_title' );
    
    /**
     * woocommerce_after_shop_loop_item hook.
     * 
     * @hooked woocommerce_template_loop_product_link_close - 5  ==> (2) From here
     * <===  <===  <===  <===  <===  <===  <===  <===  <===  <=== (1) To here
     * @hooked woocommerce_template_loop_add_to_cart - 10
     */
    do_action( 'woocommerce_after_shop_loop_item' );
    

    所以有两种方法可以实现从&lt;a href="…&gt;&lt;/a&gt;取出价格:

    1. 我们将尝试在 'woocommerce_template_loop_product_link_close' 钩住函数之后将 'woocommerce_template_loop_price' 从一个位置解钩到另一个位置。

    然后您可以尝试将此代码 sn-p 添加到您的活动子主题的 function.php 文件中:

    add_action('init', function(){
       remove_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
       add_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_price', 7);
    }
    
    1. 我们将尝试在 'woocommerce_template_loop_price' 钩子函数之前将 'woocommerce_template_loop_product_link_close' 从一个位置解钩到另一个位置。

    然后您可以尝试将此代码 sn-p 添加到您的活动子主题的 function.php 文件中:

    add_action('init', function(){
       remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
       add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 7);
    }
    

    我还没有测试它,但是这次它应该可以正常工作而不会出现错误 500。

    你也可以试试add_action('init', function(){ … }以防万一。

    最终可行的解决方案(由fjott 选择)

    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    add_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_price', 7);
    

    【讨论】:

      【解决方案2】:

      您可以禁用链接到产品@Loop 只添加 2 行代码,我已经在我的客户端商店中对其进行了测试并且它可以正常工作。您需要将下面的 2 个链接代码放入您的孩子的 functions.php 中。

      remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
      remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-14
        • 1970-01-01
        • 1970-01-01
        • 2018-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多