[英]Woocommerce add <div> after row of products
I'm trying to add shelves after each row of products in my Woocommerce shop, product categories and so on by adding <div>
elements after the <li>
of each products row. 我试图通过在每个产品行的
<li>
之后添加<div>
元素,在Woocommerce商店中的每一行产品,产品类别等之后添加货架。
<div container>
<div shelf right>
</div>
<div shelf left>
</div>
<div shelf center>
</div>
</div>
after each row of products (in my case, I've limited the columns to 3 products per row). 每行产品之后(以我为例,我将列限制为每行3个产品)。 I was able to achieve this by tinkering with the loops inside the files like wc-class-shortcodes.php, product-archive.php and such, but I was looking for a way to do that without changing the files outside of my child-theme (so it won't break the first time I update my files).
我可以通过修改wc-class-shortcodes.php,product-archive.php等文件中的循环来实现这一目标,但我一直在寻找一种无需更改子目录即可的方法,主题(这样就不会在我第一次更新文件时中断它)。
I've already tried using the hook "woocommerce_after_shop_loop_item", but it added my div inside of the <li>
of the product - Not what I wanted since if I want a shelf underneath all of the products, I need to create it after the <li>
and before the next one. 我已经尝试使用钩子“ woocommerce_after_shop_loop_item”,但是它在产品的
<li>
中添加了我的div-不是我想要的,因为如果我想在所有产品的下面都放一个架子,则需要在<li>
,然后下一个。 And also after the last product, even if it's not a full row. 甚至在最后一个产品之后,即使它不是完整的行。
I've already looked at another question: 我已经看了另一个问题:
Insert a div after the 3rd product in woocommerce shop 在woocommerce商店的第三个产品之后插入div
But the solutions they had didn't work outside of the PHP template files that I would like to keep unharmed. 但是,他们所使用的解决方案在PHP模板文件之外无法使用,我希望这些文件不会受到损害。
Does anyone have any suggestions? 有没有人有什么建议?
Try this, 尝试这个,
//Add DIV end element after shop loop item
add_action('woocommerce_after_shop_loop_item', 'action_woocommerce_after_shop_loop_item', 10, 0);
function action_woocommerce_after_shop_loop_item( ) {
echo "</div>";
};
//Add DIV start element before shop loop item
add_action('woocommerce_before_shop_loop_item', 'action_woocommerce_before_shop_loop_item', 10, 0);
function action_woocommerce_before_shop_loop_item( ) {
echo "<div class='demo_div_wrapper'>";
};
This code is worked for me. 这段代码对我有用。 Hope this will helps you.
希望这对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.