【问题标题】:Display checkbox in Woocommerce emails [duplicate]在 Woocommerce 电子邮件中显示复选框 [重复]
【发布时间】:2020-09-25 16:56:14
【问题描述】:

我在 Woocommerce 结帐中添加了一个复选框

add_filter( 'woocommerce_checkout_fields' , 'my_custom_order_notes' );

function my_custom_order_notes( $fields ) {
$fields['billing']['my_new_order_notes'] = array(
  'label'       => __('Lorem ipsum', 'woocommerce'),
    'required'    => false,
    'clear'       => false,
    'type'        => 'checkbox'
);
return $fields;
}

add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_field_value_to_order_notes', 15, 2  );

function my_custom_field_value_to_order_notes( $order_id, $data ) {
if ( ! is_object( $order_id ) ) {
  $order = wc_get_order( $order_id );
}
$order->set_customer_note( isset( $data['my_new_order_notes'] ) ? $data['my_new_order_notes'] : '' );
wc_create_order_note( $order_id, $data['my_new_order_notes'], true, true );
$order->save();
}

这是有效的,但在订购电子邮件时,它会显示“Notes:1”,如果选中该复选框,我希望它是“Lorem ipsum:yes”。我需要为此使用客户备注,因为我还使用了一个会计软件来检索 Woocommerce 订单备注,但它不会检索任何其他自定义数据,因此使用订单备注是唯一的方法。如果客户选中复选框,我如何调整我的代码以在所有订单电子邮件中显示“Lorem ipsum:是”?

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您应该只需要调整对set_customer_note 的调用:

    $order->set_customer_note(
        !empty($data['my_new_order_notes']) ? 'Yes' : 'No'
    );
    

    【讨论】:

    • 这会在订单电子邮件中显示“Notes: yes”或“Notes:no”,但我需要它来显示 Lorem ispum: yes 或 Lorem ispum: no。 (Lorem ipsum 是复选框标签)
    猜你喜欢
    • 2013-06-08
    • 1970-01-01
    • 2012-07-29
    • 2019-05-18
    • 1970-01-01
    • 2013-07-01
    • 2017-07-27
    • 2016-03-05
    • 2019-06-16
    相关资源
    最近更新 更多