我需要使用WooCommerce为产品列表页面上的图像添加包装器元素。
我正在尝试使用via函数。php是一个改变的钩子,但我不知道如何解决它
remove_action( \'woocommerce_before_shop_loop_item_title\', \'woocommerce_template_loop_product_thumbnail\', 10);
add_action( \'woocommerce_before_shop_loop_item_title\', \'woocommerce_template_loop_product_thumbnail\', 10);
if ( ! function_exists( \'woocommerce_template_loop_product_thumbnail\' ) ) {
function woocommerce_template_loop_product_thumbnail() {
echo wc_placeholder_img();
}
}
function wc_placeholder_img( $size = \'woocommerce_thumbnail\', $attr = \'\' ) {
$dimensions = wc_get_image_size( $size );
$placeholder_image = get_option( \'woocommerce_placeholder_image\', 0 );
$default_attr = array(
\'class\' => \'woocommerce-placeholder wp-post-image\',
\'alt\' => __( \'Placeholder\', \'woocommerce\' ),
);
$attr = wp_parse_args( $attr, $default_attr );
if ( wp_attachment_is_image( $placeholder_image ) ) {
$image_html = wp_get_attachment_image(
$placeholder_image,
$size,
false,
$attr
);
} else {
$image = wc_placeholder_img_src( $size );
$hwstring = image_hwstring( $dimensions[\'width\'], $dimensions[\'height\'] );
$attributes = array();
foreach ( $attr as $name => $value ) {
$attribute[] = esc_attr( $name ) . \'="\' . esc_attr( $value ) . \'"\';
}
$image_html = \'<div class="wc-img-wrapper"><img src="\' . esc_url( $image ) . \'" \' . $hwstring . implode( \' \', $attribute ) . \'/></div>\';
}
return apply_filters( \'woocommerce_placeholder_img\', $image_html, $size, $dimensions );
}