wordpress - 动态再营销代码问题。导致wordpress错误的条件逻辑
问题描述
尝试为查看到 WordPress 页脚的产品添加谷歌再营销标签,但我不断收到一条严重的错误消息。没有条件逻辑它可以正常工作,但是一旦添加我就会出错。我已经尝试了很多东西的组合,只是在旋转我的轮子,却无处可去。谁能帮我搞定这个工作?我似乎无法弄清楚出了什么问题。提前感谢您的帮助。
'''
add_action('wp_footer’, 'dehydr8ed_footer_tags');
function dehydr8ed_footer_tags() {
if (is_product() ){
global $post;
$post_id = $post->ID;
$product = wc_get_product( $post->ID );
if ( $product->is_in_stock() ) {
$price = $product->get_price();
?>
<script>
gtag('event', 'page_view', {
'send_to': '#########',
'value': ‘<?php echo ( number_format( $price, 2, '.', '') ); ?>’,
'items': [{
'id': '<?php echo ( $product->id ); ?>',
'google_business_vertical': 'retail'
}]
});
</script>
<?php
}
}
};
'''
谢谢你,JD
解决方案
解决了...
add_action('wp_footer', 'dehydr8ed_footer_tags');
function dehydr8ed_footer_tags(){
if(is_product()) {
global $product;
$id = $product->get_id();
if ( $product->is_in_stock() ) {
$price = $product->get_price();
}?>
<script>
gtag('event', 'page_view', {
'send_to': '##########',
'value': $<?php echo ( number_format( $price, 2, '.', '') ); ?>’,
'items': [{
'id': '<?php echo esc_js( $product->id ); ?>',
'google_business_vertical': 'retail'
}]
});
</script>
<?php
}
};
推荐阅读
- cloud - 什么是NetAPP?如何使用它 ?为什么我应该使用 NetAPP?
- install4j - 通过cli模式运行媒体文件时出现随机异常
- reactjs - 在 Gatsby/Contentful 中使用 Lodash get
- git - 如何获取 Azure Devops 中所有存储库的上周提交列表
- c# - 选择选项后返回 CLI 主菜单
- python - 从汤对象中选择 csv 文件 url
- r - 如何在 2 x 2 设计中处理分组数据?
- java - 以 Object 为值的 Java HashMap 以及任何扩展它的东西?
- reactjs - 反应原生平面列表更新状态循环问题
- python - 在熊猫中,目前我这样做是为了在新行中附加索引,但它不会对我的 CSV 文件进行任何更改