wordpress - WooCommerce 块:向所有产品网格添加新徽章
问题描述
尝试将新徽章添加到 WooCommerce 块中的所有产品网格。似乎没有将 span 元素合并到我的代码中。
这是我目前使用的 PHP:
add_filter('woocommerce_blocks_product_grid_item_html', 'add_new_woocommerce_blocks_product_grid_item_html', 10 , 3);
function add_new_desc_woocommerce_blocks_product_grid_item_html($content, $data, $product) {
$new_badge = '<span class="new-badge onsale">' . esc_html__( 'NEW', 'woocommerce' ) . '</span>';
$after_link_pos = strpos($content, "</a>");
$before = substr($content, 0, $after_link_pos + 4);
$after = substr($content, $after_link_pos + 4);
$content = $before . $new_badge . $after;
return $content;
}
解决方案
推荐阅读
- c# - 无法从 c# 项目中读取 app.config 文件
- c++ - 零初始化、未命名、临时 unsigned int
- python - API 请求 - ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
- html - 为什么我的 iframe 嵌入有覆盖此图像的文本?
- r - 正则表达式匹配冒号周围的数字或数字,但不在某些字符串之后
- r - 我已经为 PCA 标记了数据矩阵。如何使用 r 根据 PCA 中的每个标签为它们着色?
- ios - swift - 使用 Apple 登录“注册未完成”错误
- arrays - 在 Ruby 中排序并没有达到我对子数组的期望
- azure-devops - SonarQube/Azure DevOps 代码分析失败 - .scannerwork/report-task.txt 未找到
- javascript - 我的函数正在返回 [对象承诺]