首页 \ 问答 \ 如何使用str_replace,WordPress钩子和WooCommerce函数(How to use str_replace, WordPress hooks, and WooCommerce functions)

如何使用str_replace,WordPress钩子和WooCommerce函数(How to use str_replace, WordPress hooks, and WooCommerce functions)

在WooCommerce中,有一个主要的模板,一切都在运行。

这里: https//github.com/woothemes/woocommerce/blob/master/woocommerce-template.php#L1315

line 1315line 1315 ,我们开始使用html进行结帐,但问题是所有内容都在<p>标记中。 我想将其更改为<div><li><dd> (未定)。 尽管如此,我想改变标签。

我希望通过str_replace("<p","<div",$some_variable);来做到这str_replace("<p","<div",$some_variable);str_replace("/p>","/div>",$some_variable); 但我对于要调用的钩子感到非常困惑。

哦,我不编辑主文件的原因是因为插件的每次更新都会被覆盖并且效率低下:]


In WooCommerce there is the main template which everything runs off.

Here: https://github.com/woothemes/woocommerce/blob/master/woocommerce-template.php#L1315

At line 1315 and down we begin the html for a checkout, but the problem is everything is in a <p> tag. I want to change it to a <div> or <li> or <dd> (undecided). Nonetheless, I want to alter the tag.

I am hoping to do it via a str_replace("<p","<div",$some_variable); and a str_replace("/p>","/div>",$some_variable); but am seriously confused on what hook to be calling.

Oh, and the reason I'm not editing the main file is since every update for the plugin it would be overwritten and inefficient :]


原文:https://stackoverflow.com/questions/15378045
更新时间:2023-03-25 09:03

最满意答案

$do_not_text == ''评估为true。 为什么? 因为没有定义$do_not_text ,这是一个假值。 您将它与空字符串进行比较,该字符串也等同于虚假值。 因此比较成立,导致第一个if语句被评估为true。


$do_not_text == '' evaluates to true. Why? Because $do_not_text is not defined which is a falsy value. You are comparing it to an empty string which also equates to a falsy value. So that comparison is true causing the first if statement to be evaluated as true.

相关问答

更多
  • 这在布尔文和类型比较表的PHP文档中有介绍。 转换为布尔值时,以下值被认为是FALSE: 布尔FALSE本身 整数0 (零) 浮点数0.0 (零) 空字符串和字符串'0' 具有零元素的数组 具有零成员变量的对象(仅限PHP 4) 特殊类型的NULL (包括未设置的变量) 由空标签创建的SimpleXML对象 其他每个值均被视为“真” 。 This is covered in the PHP documentation for booleans and type comparison tables. When ...
  • PHP的一个常见习惯是让函数返回一些有意义的值,或者在某些失败的情况下使用布尔值FALSE 。 在fgetcsv的情况下,当没有更多值要返回时,返回索引数组或返回FALSE 。 使用=== TRUE在这里根本不起作用 - 索引数组不是布尔值TRUE ,但最明确的是!== FALSE 。 A common idiom of PHP is to have a function return some meaningful value, or a boolean FALSE in case of some fai ...
  • 最后,我只是自己想出了它。 只需在ajax调用中使用async: false 。 现在它工作正常。 Plus创建一个空变量并在其中存储布尔值,然后在ajax调用之后返回该变量。 这是我以前的代码: require 'nmp_process.php'; add_action('wp_ajax_nmp_process_ajax', 'nmp_process_func'); add_action('wp_ajax_nopriv_nmp_process_ajax', 'nmp_process_func') ...
  • 就像Raveren说的那样,你不能发送整数或布尔值到PHP。 所有发送的数据始终是字符串。 如果你仍然想使用if($ post)而不是if($ post =='true'),那么使用switch switch($post) { case "true": $post = true; break; case "false": $post = false; break; } if ($post) { ... } 没有其他办 ...
  • 找到匹配项时, array_search会返回指针。 只有在找不到匹配时才返回false。 这就是为什么在你的情况下只有相反的工作原因。 如果在数组中找到针,则返回针的键,否则返回FALSE。 array_search returns you needle when a match is found. it returns false only when match is not found. This is why only the opposite works in your case. Returns ...
  • $do_not_text == ''评估为true。 为什么? 因为没有定义$do_not_text ,这是一个假值。 您将它与空字符串进行比较,该字符串也等同于虚假值。 因此比较成立,导致第一个if语句被评估为true。 $do_not_text == '' evaluates to true. Why? Because $do_not_text is not defined which is a falsy value. You are comparing it to an empty string w ...
  • 当一个字符串与一个整数进行比较时,该字符串将自动转换为一个整数,在您的情况下,该字符串没有数字,因此它将被评估为零,从而满足相等性,您有两个选择: if ('0' == 'tr') 要么 if (0 === 'tr') ===表示检查值和类型 。 我还发现这对PHP手册有帮助: 该值由字符串的初始部分给出。 如果字符串以有效数字数据开头,则这将是使用的值。 否则,该值将为0(零) When a string is compared to an integer, the string will be conv ...
  • 引用自: http://php.net/manual/en/language.operators.comparison.php 如果在类型杂耍之后$ a等于$ b,$ a == $ b为TRUE 如果您将数字与字符串进行比较或比较涉及数字字符串,则每个字符串将转换为数字,并且数字执行比较 因此,因为您的字符串都是数字的,所以它们首先被转换为数字。 然后在一些架构上数字是如此之大,以至于溢出最大整数大小并且你得到相同的结果。 Quote from: http://php.net/manual/en/langu ...
  • 构造函数始终返回类的新实例 。 您不能从构造函数返回任何其他类型的值。 构建代码的更好方法是: source: signup.php class Signup { public $success; protected function buildProfile() { if($logic){ $this->success = true; }else{ $this->success = false; ...
  • 你的困惑都归结为对优先权的误解。 一个数学类似物将是“零等于零的任何东西”。 考虑下面的表达式: 0 x 100 + 5 在任何编程语言或一个体面的计算器中,这个评估为5.“零时间任何事情”公理是真实的 - 但在这种情况下,“任何事情”是100 ,而不是100 + 5 ! 要明白为什么,请将其与此进行比较: 5 + 0 x 100 无论您是在开头还是结尾添加5,运算符优先规则都会消除语句中的不明确性。 在JavaScript布尔逻辑中, &&优先级高于|| 。 由于每个操作员都是可交换的 ,所以写作 f ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)