我希望能够从数组中获取某些元值,例如WooCommerceEventsAttendeEname
、WooCommerceEventsAttendeElastName
、FooEvents_Custom_State/Pavinic
、FooEvents_Custom_Address
、FooEvents_Custom_Title
等。
这个PHP代码段将添加一个字段的订单电子邮件,但我如何编辑这一点,我可以让它显示一些元从数组?
/**
* Add a custom field (in an order) to the emails
*/
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$fields['meta_key'] = array(
'label' => __( 'Label' ),
'value' => get_post_meta( $order->id, 'meta_key', true ),
);
return $fields;
}
对于特定的WooCommerce订单,我使用
echo '<pre>'; print_r( get_post_meta( '4609', 'WooCommerceEventsOrderTickets', true ) ); echo '</pre>';
这表明:
Array
(
[1] => Array
(
[1] => Array
(
[WooCommerceEventsProductID] => 454
[WooCommerceEventsOrderID] => 4609
[WooCommerceEventsTicketType] =>
[WooCommerceEventsStatus] => Unpaid
[WooCommerceEventsCustomerID] => 64
[WooCommerceEventsAttendeeName] => AttendeeFirst
[WooCommerceEventsAttendeeLastName] => AttendeeLast
[WooCommerceEventsAttendeeEmail] => jon@freshysites.com
[WooCommerceEventsAttendeeTelephone] => 607-123-4567
[WooCommerceEventsAttendeeCompany] =>
[WooCommerceEventsAttendeeDesignation] =>
[WooCommerceEventsVariations] => Array
(
[attribute_pa_registration-options] => nassgap-member
)
[WooCommerceEventsVariationID] => 4078
[WooCommerceEventsPrice] => $675.00
[WooCommerceEventsPurchaserFirstName] => Jon
[WooCommerceEventsPurchaserLastName] => Fuller
[WooCommerceEventsPurchaserEmail] => freshyjon@gmail.com
[WooCommerceEventsCustomAttendeeFields] => Array
(
[fooevents_custom_address] => 123 Attendee St
[fooevents_custom_city] => Attendee City
[fooevents_custom_state/province] => Nevada
[fooevents_custom_postal_code] => 13813
[fooevents_custom_organization] => Attendee LLC
[fooevents_custom_title] => Attendee Title
)
)
)
)
尝试下面这样的方法(因为我不能真正测试它,您可能应该安排它):
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$event = get_post_meta( $order->get_id(), 'WooCommerceEventsOrderTickets', true );
if( ! is_array($event) ) return $fields;
$event = isset($event[1][1]) ? $event[1][1] : '';
if( sizeof($event) == 0 ) return $fields;
$custom = isset($event['WooCommerceEventsCustomAttendeeFields']) ? $event['WooCommerceEventsCustomAttendeeFields'] : '';
// Set our array of needed data
$fields_array = [
__('First name') => isset($event['WooCommerceEventsAttendeeName']) ? $event['WooCommerceEventsAttendeeName'] : '',
__('Last name') => isset($event['WooCommerceEventsAttendeeLastName']) ? $event['WooCommerceEventsAttendeeLastName'] : '',
__('Title') => isset($custom['fooevents_custom_title']) ? $custom['fooevents_custom_title'] : '',
__('Organization') => isset($custom['fooevents_custom_organization']) ? $custom['fooevents_custom_organization'] : '',
__('Address') => isset($custom['fooevents_custom_address']) ? $custom['fooevents_custom_address'] : '',
__('City') => isset($custom['fooevents_custom_city']) ? $custom['fooevents_custom_city'] : '',
__('Postcode') => isset($custom['fooevents_custom_postal_code']) ? $custom['fooevents_custom_postal_code'] : '',
__('State') => isset($custom['fooevents_custom_state/province']) ? $custom['fooevents_custom_state/province'] : '',
];
// Loop though the data array to set the fields
foreach( $fields_array as $label => $value ){
if( ! empty($value) ){
$fields[] = array(
'label' => $label,
'value' => $value,
);
}
}
return $fields;
}
代码放在活动子主题(或活动主题)的function.php文件中。应该管用。
您将得到如下内容:
我添加了自定义状态: 我添加了自定义电子邮件: 我可以在电子邮件设置中看到电子邮件,在订单状态下拉菜单中看到状态。现在,每当订单状态更改为时,我就需要发送我的新电子邮件。过渡钩似乎从未开火。 我也试过: 这似乎也不起作用...有什么想法吗?
在Woocommerce中,我使用“在管理订单中显示Woocommerce自定义签出字段值使其可编辑”回答代码,在管理订单页面中显示自定义字段值,效果良好。 我的问题:是否可以在电子邮件通知中显示该自定义字段值?
我创建了一个自定义电子邮件类并将其添加到Woocommerce中。当我转到WooCommerce中的电子邮件设置时,我可以在那里看到我的模板,当我手动触发它时,电子邮件就会到达目标电子邮件帐户。现在我遇到的问题是,我在我的类中添加了一个动作,该动作应该检测订单状态更改,并在订单被设置为我的自定义状态时执行我的触发器功能: add_action('woocommerce_order_status_w
我在这个相关的答案中找到了对我的问题的部分和可行的答案: send-an-email-notification-when-order-status-changhe-fron-pendig-to-cancelled 我正在考虑使用提供的解决方案,但想看看我是否可以更改电子邮件通知,明确地说,“未决付款订单现在取消”,所以它不同于常规取消的订单。 我该怎么做?
好的,基本上我们在我们的WooCommerce商店中使用ACF创建了一个自定义字段,以便为特定的产品添加一个“发货延迟”通知。