如何使用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 1315
和line 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 astr_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
最满意答案
$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中的真假工作如何?(How does true/false work in PHP?)[2023-09-03]
这在布尔文和类型比较表的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 ...
-
在wordpress中返回true和false的Ajax函数问题(Ajax function issue on return true and false in wordpress)[2023-08-29]
最后,我只是自己想出了它。 只需在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 ...