从 content-product.php 模板的产品价格中删除产品 Link
Removing product Link from the product price on content-product.php template
我正在使用 Woocommerce WP 插件。在我的商店页面上,我想从 <span class="price">
.
中删除 link <a>
到产品页面
在 this 文章中,作者建议更改 /your-child-theme/woocommerce/content-product.php WooCommerce 模板中的标签,但这不再是可能在最新的 WooCommerce 版本 2.6+ 中。
我只找到了一种方法来删除整个 link,而不仅仅是价格-link。
如何只从价格移动 link?
这是我想要的:
<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 -->
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' );
所以有 2 个替代方案可以实现从 <a href="…></a>
中取出价格:
- 我们将尝试在
'woocommerce_template_loop_product_link_close'
挂钩后将 'woocommerce_template_loop_price'
从一个位置解开到另一个位置功能。
然后您可以尝试将此代码片段添加到您的活动子主题的 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);
}
- 我们将尝试在
'woocommerce_template_loop_price'
挂钩之前将 'woocommerce_template_loop_product_link_close'
从一个位置解开到另一个位置功能。
然后您可以尝试将此代码片段添加到您的活动子主题的 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);
您可以禁用 Link 到 Products @ Loop 只添加 2 行代码,我已经在我的客户商店中测试它并且它的工作。您需要将下面的 2 link 代码放入您的 child-them 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 );
我正在使用 Woocommerce WP 插件。在我的商店页面上,我想从 <span class="price">
.
<a>
到产品页面
在 this 文章中,作者建议更改 /your-child-theme/woocommerce/content-product.php WooCommerce 模板中的标签,但这不再是可能在最新的 WooCommerce 版本 2.6+ 中。
我只找到了一种方法来删除整个 link,而不仅仅是价格-link。
如何只从价格移动 link?
这是我想要的:
<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 -->
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' );
所以有 2 个替代方案可以实现从 <a href="…></a>
中取出价格:
- 我们将尝试在
'woocommerce_template_loop_product_link_close'
挂钩后将'woocommerce_template_loop_price'
从一个位置解开到另一个位置功能。
然后您可以尝试将此代码片段添加到您的活动子主题的 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);
}
- 我们将尝试在
'woocommerce_template_loop_price'
挂钩之前将'woocommerce_template_loop_product_link_close'
从一个位置解开到另一个位置功能。
然后您可以尝试将此代码片段添加到您的活动子主题的 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);
您可以禁用 Link 到 Products @ Loop 只添加 2 行代码,我已经在我的客户商店中测试它并且它的工作。您需要将下面的 2 link 代码放入您的 child-them 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 );