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' );
所以有两种方法可以实现从<a href="…></a>取出价格:
- 我们将尝试在
'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);
}
- 我们将尝试在
'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);