这看起来很奇怪,但我试图在元素(按钮)之后添加背景图像,但由于某种原因,图像没有显示。
.single_add_to_cart_button:after {
content: '';
width: 50px;
height: 9px;
display: inline-block;
background: url(/images/arrow.png);
background-position: 50%;
background-size: cover;
background-repeat: no-repeat;
}
<button type="submit" class="single_add_to_cart_button button alt disabled wc-variation-selection-needed">Place order</button>
由于某种原因,图片没有显示,我什至尝试使用实时 URL
注意:如果我尝试使用一个段落,它会像您在我的笔中看到的那样起作用 here
如何在添加到购物车按钮后从模板目录添加图像?
在一个更简单的解决方案中,我尝试使用钩子(Hook),但我也很难使用 bloginfo 访问图像:
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart_button_func' );
function add_content_after_addtocart_button_func() {
echo '<img src="<?php bloginfo("template_directory")/images/logo/logo.png">';
}
最佳答案
使用 <?php
时出现语法错误在 echo 语句中以及 bloginfo($option)
回显一个值,因此要求您使用 get_template_directory_uri()
获取将返回字符串的模板目录的路径
您的代码将如下所示:
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart_button_func' );
function add_content_after_addtocart_button_func() {
echo '<img src="'.get_template_directory_uri().'/images/logo/logo.png">';
}
关于html - Woocommerce 在添加到购物车按钮后添加图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56336298/