签入 header if 'thank you' 页面 - Opencart 2

Check in header if 'thank you' page - Opencart 2

在 OpenCart 2 中,我只在“成功”/“谢谢”页面中编辑 header 的 appearance/php (catalog/view/theme/*/template/common/success .tpl).

所以,在 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 中设置变量,然后打印 header,但没有结果。

你可以尝试这样的事情(根据你的 URL 去做):

<?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(域后的部分),围绕 / 符号拆分它,然后检查它是否以 success.tpl

结尾

您也可以为 end($parameters) 而不是 if 创建 switch

我不知道 opencart 结构,但如果这个值永远不会改变,你可以尝试使用 strpos/stripos,比如:

if(stripos($var_with_page_title, 'thank you') !== false) {
    do_something();
}

如果您希望检测页眉中的 checkout/success 页面,请执行以下操作:

打开 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'];
}

现在 catalog/view/theme/YOUR_THEME/template/common/header.tpl

随意添加

<?php if ($success) { ?>
  //do something
  <?php if ($success_email) { ?><?php echo $success_email; ?><?php } ?>
<?php } ?>

奖励邮件