简体   繁体   English

在PHP中使用Wordpress Shopp中的变量

[英]Using a variable from wordpress shopp in php

I'm using the Shopp E-commerce plugin for Wordpress 我正在为Wordpress使用Shopp电子商务插件

I want to use some data that is provided by this plugin. 我想使用此插件提供的一些数据。 I want to use the payment method in a PHP if statement. 我想在PHP if语句中使用付款方式 To do this I need to get the data in a variable 为此,我需要获取变量中的数据

The plugin provides only a piece of code that actually displays the value. 该插件仅提供一段实际显示该值的代码。

<?php shopp('purchase', 'paymethod'); ?>

But I want to have this data in a variable 但我想将此数据放在一个变量中

$paymentmethod = ...

I'm having problems to get the shopp data in the variable. 我在获取变量中的shopp数据时遇到问题。 How can I do this? 我怎样才能做到这一点?

Solved: 解决了:

Great, you helped me out a lot. 太好了,您帮了我很多忙。 This is what i got: For future reference this translates the payment method provided by the shopp plugin to another description that is needed for an integration with the trusted shops certificate. 这就是我得到的:为了将来参考,这将shopp插件提供的付款方式转换为与受信任的商店证书集成所需的另一种描述。 It probably could be a lot cleaner but this works. 可能会干净很多,但这行得通。

<?php 
$paymentmethod = shopp('purchase', 'paymethod',  array('return'=>true)); 
if ($paymentmethod == vorkasse)
echo "PREPAYMENT";
else 
echo "OTHER PAYMENT";
?>

If I read the manual, there is an 'options' parameter you can use. 如果我阅读了手册,则可以使用“ options”参数。 Read the manual for more information (I can't test this for you, I don't have an install), but it will look something like this 阅读手册以获取更多信息(我无法为您测试,我没有安装),但是它看起来像这样

$paymentmethod = shopp('purchase', 'paymethod', array('return'=>true)); 

You should play around a bit, because it is not completely clear how this works. 您应该多做一些尝试,因为尚不清楚它是如何工作的。 There is also the 'echo' option, which does the reverse of the return option (I think), but the manual says it does so on false . 还有一个'echo'选项,它与return选项相反(我认为),但是手册说它在false上这样做。 That would be strange. 那太奇怪了。

return : when set to true, 1, or on, this option forces the tag to return the value instead of displaying/echoing the value to the page. return :设置为true,1或on时,此选项强制标记返回值,而不是在页面上显示/回显该值。 Alternatively, prefix the tag parameter with get to get the same effect. 或者,在tag参数前加上get以获得相同的效果。 All theme api tags that return a boolean value will return by default. 默认情况下,将返回所有返回布尔值的主题api标签。
echo : when set to false, 0, or off, this option forces the tag to display the value to the page. echo :设置为false,0或off时,此选项强制标记将值显示在页面上。 This is the default for all non-boolean tags. 这是所有非布尔值标记的默认值。

You might need to provide the 'echo' paramter as wel. 您可能需要提供“ echo”参数。 But some combination of these should work :) 但是这些的某种组合应该起作用:)

A shorthand for writing shopp() commands has been added to the Shopp API. Shopp API中已添加了用于编写shopp()命令的简写。

This: $paymentmethod = shopp('purchase', 'paymethod', 'return=true'); 这: $paymentmethod = shopp('purchase', 'paymethod', 'return=true');

can now be written as: $paymentmethod = shopp('purchase.get-paymethod'); 现在可以写成: $paymentmethod = shopp('purchase.get-paymethod');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM