问题描述
在OpenCart 2中,我仅在“成功” /“谢谢”页面(目录/视图/主题/*/template/common/success.tpl)中编辑标题的外观/PHP。
因此,在catalog / view / theme / * / template / common / header.tpl中,我想执行以下操作:
if( $is_thank_you_page ){
echo "stuff";
// bonus: I wanted to get the order email but maybe it should be a different post
}
但是如何检查header.tpl
是否是“成功” /“谢谢”页面?
我尝试在success.tpl
中设置变量,然后再打印无结果的标题。
解决方法
您可以尝试执行以下操作(根据您的网址进行操作):
<?php
$parameters = explode('/',$_SERVER['REQUEST_URI']);
if(end($parameters) === 'success.tpl'){
//the condition with $parameters depends on the exact look of your URL
//you could also access an index directly
}
基本上,它使用REQUEST_URI(域之后的一部分),将其分割为/符号,然后检查其是否以成功结尾。tpl
您也可以为switch
制作一个end($parameters)
,而不是if
。
我不知道opencart的结构,但是如果这个值永远不变,您可以尝试使用strpos / stripos,如下所示:
if(stripos($var_with_page_title,'thank you') !== false) {
do_something();
}
,
如果要在标题中检测到结帐/成功页面,请执行以下操作:
打开 catalog / controller / common / header.php
找到
// Menu
$this->load->model('catalog/category');
添加之前
// success page checking
$data['success'] = '';
if (isset($this->request->get['route']) && $this->request->get['route'] == 'checkout/success') {
$data['success'] = true;
}
// looking for email from the order
$data['success_email'] = '';
if ($this->customer->isLogged()) {
$data['success_email'] = $customer_info['email'];
} elseif (isset(this->session->data['guest']['email'])) {
$data['success_email'] = $this->session->data['guest']['email'];
}
现在进入目录/视图/主题/YOUR_THEME/template/common/header.tpl
在您喜欢的任何地方添加
<?php if ($success) { ?>
//do something
<?php if ($success_email) { ?><?php echo $success_email; ?><?php } ?>
<?php } ?>
带有奖励电子邮件