从meta_key值获取特定值

时间:2019-03-12 10:18:36

标签: php wordpress woocommerce

我的数据库中有一个key_value,看起来像这样:(一长列变量)

a:1:{i:44249684;a:4:{s:11:"shipment_id";i:44249684;s:6:"status";s:37:"onderweg - overhandigd aan vervoerder";s:10:"tracktrace";s:15:"3SMYPA463136003";s:8:"shipment";a:31:{s:2:"id";i:44249684;s:9:"parent_id";N;s:10:"account_id";i:113337;s:7:"shop_id";i:24978;s:13:"shipment_type";i:1;s:9:"recipient";a:11:{s:2:"cc";s:2:"NL";s:4:"city";s:6:"Stadsnaam";s:6:"person";s:13:"John Doe";s:7:"company";s:4:"John";s:5:"email";s:22:"pphendriksma@gmail.com";s:5:"phone";s:10:"0650656148";s:22:"street_additional_info";s:0:"";s:11:"postal_code";s:6:"3992JW";s:6:"street";s:12:"Mispelgaarde";s:6:"number";s:2:"40";s:13:"number_suffix";s:0:"";}s:6:"sender";a:10:{s:2:"cc";s:2:"NL";s:11:"postal_code";s:6:"1234AB";s:4:"city";s:7:"Cityname";s:6:"street";s:10:"Streetname";s:6:"number";s:1:"3";s:13:"number_suffix";s:0:"";s:6:"person";s:28:"T.a.v. Retouren en Reparatie";s:7:"company";s:18:"Car Care Nederland";s:5:"email";s:24:"info@companyemail.com";s:5:"phone";s:10:"1234567890";}s:6:"status";i:3;s:7:"options";a:9:{s:12:"package_type";i:1;s:14:"only_recipient";i:0;s:9:"signature";i:1;s:6:"return";i:0;s:12:"large_format";i:0;s:17:"label_description";s:19:"invoice-number";s:9:"age_check";i:0;s:13:"delivery_type";i:4;s:13:"delivery_date";s:19:"2019-03-12 00:00:00";}s:16:"general_settings";a:4:{s:22:"save_recipient_address";i:1;s:10:"tracktrace";a:10:{s:32:"carrier_email_basic_notification";i:1;s:23:"send_track_trace_emails";i:1;s:26:"email_on_handed_to_courier";i:1;s:3:"bcc";i:0;s:21:"delivery_notification";i:1;s:18:"from_address_email";s:24:"info@companyemail.com";s:20:"from_address_company";s:30:"Company address";s:9:"bcc_email";s:24:"info@companyemail.com";s:7:"send_to";s:22:"customer@email.com";s:7:"send_on";s:19:"2019-03-11 02:21:34";}s:21:"delivery_notification";i:1;s:27:"delivery_notification_email";a:1:{i:0;s:24:"info@companyemail.com";}}s:6:"pickup";a:7:{s:11:"postal_code";s:6:"1234AB";s:6:"street";s:10:"Streetname";s:4:"city";s:6:"Cityname";s:6:"number";s:2:"57";s:13:"location_code";s:6:"205786";s:17:"retail_network_id";s:8:"PNPNL-01";s:13:"location_name";s:5:"shop-name";}s:19:"customs_declaration";N;s:19:"physical_properties";a:10:{s:14:"carrier_height";i:160;s:13:"carrier_width";i:205;s:14:"carrier_weight";i:820;s:14:"carrier_length";i:225;s:14:"carrier_volume";i:7380;s:6:"height";i:0;s:5:"width";i:0;s:6:"length";i:0;s:6:"volume";i:0;s:6:"weight";i:0;}s:7:"created";s:25:"2019-03-10T00:00:00+01:00";s:8:"modified";s:25:"2019-03-11T22:33:18+01:00";s:20:"reference_identifier";s:19:"CCNL-286-2019-03-12";s:10:"created_by";i:21848;s:11:"modified_by";i:21848;s:18:"transaction_status";s:4:"paid";s:7:"barcode";s:15:"3SMYPA463100973";s:5:"price";a:2:{s:6:"amount";i:575;s:8:"currency";s:3:"EUR";}s:6:"region";s:2:"NL";s:17:"external_provider";N;s:20:"external_provider_id";N;s:14:"payment_status";s:4:"paid";s:10:"carrier_id";i:1;s:11:"platform_id";i:1;s:6:"origin";s:11:"woocommerce";s:10:"user_agent";s:60:"Wordpress/5.1 WooCommerce/3.5.5 MyParcelNL-WooCommerce/3.1.3";s:19:"secondary_shipments";a:0:{}s:28:"multi_collo_main_shipment_id";N;}}}

此键值可以在meta_key:“ _ myparcel_shipments”中找到。 此meta_key在表“ wp_postmeta”中。

我目前正在尝试通过以下代码片段在发票PDF上添加跟踪:

// Adding the T-T number to the billing address
add_filter('wpo_wcpdf_after_billing_address', 'wpo_wcpdf_add_tt_number', 10, 2);
function wpo_wcpdf_add_tt_number ( $template_type, $order ) {
if ( !empty( $order->get_meta('_myparcel_shipments') ) && $template_type == 'invoice' ) {
    printf("<span class='vat_number'>Track en trace: %s</span>", $order->get_meta('_myparcel_shipments') );
}
}

此代码段与另一个meta_key完美配合。但是不同之处在于,另一个Meta_key仅具有1个单个key_value,并且没有我在此问题顶部粘贴的key_value一样大。 我感兴趣的一长串变量中,仅有的一部分是: s:10:“ tracktrace”; s:15:“ 3SMYPA463136003 ”; s:8:“

这是我想要达到的结果:

Track en trace: 3SMYPA463136003

或使用HTML:

<span class="vat_numer">Track en trace: 3SMYPA463136003</span>

黑体字的值是我想在发票上显示的部分。它在值的开头。我对PHP的知识非常了解,其他人为我编写了上面的代码段。不幸的是,他目前无法帮助我。

为了证明代码中存在某种形式的规则性,还有其他一些形式:

s:10:"tracktrace";s:13:"3SMYPA3002252";s:8:"
s:10:"tracktrace";s:13:"3SMYPA1004047";s:8:"
s:10:"tracktrace";s:15:"3SMYPA300504864";s:8:"
s:10:"tracktrace";s:15:"3SMYPA600206705";s:8:"
s:10:"tracktrace";s:13:"3SMYPA2004858";s:8:"
s:10:"tracktrace";s:15:"3SMYPA700795279";s:8:"

有人可以向我解释如何过滤掉我需要的部分,以便我的代码段给出正确的结果吗?

*出于隐私原因,我编辑了Track跟踪编号以及隐藏的客户名称,地址和其他个人数据。

0 个答案:

没有答案