所以我正在研究带有 child 主题的 WooCommerce。我创造了我的结构,
/themes/child/woocommerce/checkout/review-order.php
我的目标只是向页面添加一些“静态文本”。
例如,
<h2>Purchase Disclaimer</h2>
内
review-order.php
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<h2>Purchase Disclaimer</h2>
我的问题是,当我查看页面时,它会消失,
<h2>Purchase Disclaimer</h2>
<h2>Purchase Disclaimer</h2>
我不知道为什么它似乎加载了 2 次。这是一个小故障,还是我加载它很奇怪?也许有人可以帮助我澄清这个问题。
提前致谢
最佳答案
Checkout review-order table 第一次加载,然后 ajax 进行第二次加载(假设用于更新目的),因此您必须使用一些条件来避免这种情况:
<?php if(!defined( 'DOING_AJAX' )): ?>
<h2>Purchase Disclaimer</h2>
<?php endif; ?>
你应该避免
<h2>
标记,因为它已经用于 <h3 id="order_review_heading">Your order</h3>
或者,您可以使用 中的 Hook 函数代替
woocommerce_checkout_before_order_review
以这种方式 Hook :add_action('woocommerce_checkout_before_order_review', 'my_custom_funtion');
function my_custom_funtion(){
?>
<h2>Purchase Disclaimer2</h2>
<?php
}
此代码位于事件子主题(或主题)的 function.php 文件或任何插件 php 文件中。
关于php - 自定义 WooCommerce review-order.php 结帐模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40922394/