【问题标题】:Check in header if 'thank you' page - Opencart 2如果“谢谢”页面检查标题 - Opencart 2
【发布时间】:2020-09-01 02:46:55
【问题描述】:

在 OpenCart 2 中,我仅在“成功”/“谢谢”页面 (catalog/view/theme/*/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 opencart opencart2.x


    【解决方案1】:

    你可以尝试这样的事情(根据你的 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

    【讨论】:

    • 这帮助我思考了我最终使用的 UTM。感谢您的帮助和想法!
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      如果您希望在标题中检测结帐/成功页面,请执行以下操作:

      打开目录/控制器/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 } ?>
      

      使用奖励电子邮件

      【讨论】:

      • 不,不幸的是两者都不起作用。我知道我需要以$data['foo'] 的形式设置变量,但可能到那时电子邮件已从会话中清除。然后我又不知道为什么$data['success']没有通过
      • 您是否清除了 OCMOD 缓存?电子邮件正在从会话中清除,但不仅仅是在结帐后。明天我会再次测试并更新答案。保持联系。 $data['success'] 应该可以,已经检查过了
      猜你喜欢
      • 2023-03-20
      • 2019-12-29
      • 1970-01-01
      • 2013-08-09
      • 1970-01-01
      • 2021-11-03
      • 2012-06-26
      • 2015-03-04
      • 1970-01-01
      相关资源
      最近更新 更多