0

我在 wordpress 序列化数据中遇到问题。我正在开发一个与 woocommerce 相关的自定义插件。我在 woocommerce 设置部分添加了结帐部分。我还在我的插件部分提供了相同的设置更新表单,这是左侧菜单中的新菜单选项。

当我通过 woocommerce 设置部分保存数据时,它将数据作为序列化数据存储在 wp_options 表中。下面是例子:

a:18:{s:7:"启用";s:3:"yes";s:9:"test_mode";s:2:"no";s:19:"is_application_name";s:0:" ";s:10:"is_api_key";s:0:"";s:17:"order_customtable";s:0:"";s:16:"order_customflds";s:0:"";s:23 :"order_product_customfld";s:0:"";s:14:"is_merchant_id";s:0:"";s:5:"title";s:12:"Infusionsoft";s:9:"tax_label" ;s:9:"销售税";s:16:"is_free_shipping";s:2:"no";s:11:"description";s:20:"通过 Infusionsoft 付款";s:5:"卡";s:16:"VISA MASTERCARD";s:14:"wooorderstatus";s:0:"";s:14:"thanks_message";s:39:"谢谢。您的订单已收到";s :5:"调试";s:2:“否”;s:11:"debug_email";s:0:"";s:13:"http_post_key";s:0:"";}

从我的插件页面,在表单提交时,我正在获取字段值并创建一个数组,如下所示:

数组 ( [已启用] => 是 [test_mode] => 否 [is_application_name] => [is_api_key] => [order_customtable] => [order_customflds] => [order_product_customfld] => [is_merchant_id] => [title] => Infusionsoft [tax_label] => 销售税 [is_free_shipping] => 没有 [description] => 通过 Infusionsoft [cards] 付款 => VISA MASTERCARD [wooorderstatus] => [thanks_message] => 谢谢。您的订单已收到 [debug] = > 没有 [debug_email] => [http_post_key] => )

现在使用函数 update_option 对选项进行序列化和更新,它将把数据保存在数据库中,如下所示:

s:597:"a:18:{s:7:"已启用";s:3:"yes";s:9:"test_mode";s:2:"no";s:19:"is_application_name"; s:0:"";s:10:"is_api_key";s:0:"";s:17:"order_customtable";s:0:"";s:16:"order_customflds";s:0:" ";s:23:"order_product_customfld";s:0:"";s:14:"is_merchant_id";s:0:"";s:5:"title";s:12:"Infusionsoft";s: 9:"tax_label";s:9:"销售税";s:16:"is_free_shipping";s:2:"no";s:11:"description";s:20:"通过 Infusionsoft 付款";s :5:"卡片";s:15:"VISA MASTERCARD";s:14:"wooorderstatus";s:0:"";s:14:"thanks_message";s:39:"谢谢。您的订单已收到";s:5:"

请在这个问题上帮助我。

4

1 回答 1

2

不要自己序列化数组,update_option如果需要会这样做。

https://developer.wordpress.org/reference/functions/update_option/

于 2017-01-18T13:25:57.170 回答