我已在签出页面中添加了一个复选框:
add_action(\'woocommerce_after_order_notes\', \'client_already_field\');
function client_already_field( $checkout ) {
echo \'<div id="client-already-field"><h3>\'.__(\'CLIENT ALREADY? \').\'</h3>\';
woocommerce_form_field( \'client_already_checkbox_yes\', array(
\'type\' => \'checkbox\',
\'class\' => array(\'input-checkbox-yes\'),
\'label\' => __(\'YES!\'),
\'required\' => false,
), $checkout->get_value( \'client_already_checkbox_yes\' ));
echo \'</div>\';
}
并将其保存到order meta(这两个函数都起作用):
//1
add_action(\'woocommerce_checkout_update_order_meta\', \'client_already_order_meta_yes\');
function client_already_order_meta_yes( $order_id ) {
if ($_POST[\'client_already_checkbox_yes\']) update_post_meta( $order_id, \'Client Already:Yes\', esc_attr($_POST[\'client_already_checkbox_yes\']));
}
// 2
function client_already_order_meta_yes( $order_id ) {
if( !empty( $_POST[\'client_already_checkbox_yes\'] ) && $_POST[\'client_already_checkbox_yes\'] == 1 )
update_post_meta( $order_id, \'Client Already:YES\', 1 );
}
但当我勾选方框并完成交易时,收到的管理订单电子邮件中没有显示任何内容。我尝试过的事情:
// 1
add_filter( \'woocommerce_email_order_meta_fields\', \'client_already_email\', 10, 3 );
function client_already_email( $fields, $sent_to_admin, $order_obj ) {
$is_yes = get_post_meta( $order_obj->get_order_number(), \'client_already_checkbox_yes\', true );
if( empty( $is_yes ) )
return $fields;
$fields[\'client_already_checkbox_yes\'] = array(
\'label\' => __( \'Client Already\' ),
\'value\' => \'Yes\'
);
return $fields;
}
// 2
function client_already_email( $fields, $sent_to_admin, $order_obj ) {
$is_yes = get_post_meta( $order_obj->get_order_number(), \'client_already_checkbox_yes\', true );
if( empty( $is_yes ) )
return $fields;
echo "Client Already? Yes";
);
return $fields;
}
// 3
function client_already_email( $fields, $sent_to_admin, $order ) {
$fields[\'client_already_checkbox_yes\'] = array(
\'label\' => __( \'Client Already? YES\' ),
\'value\' => get_post_meta( $order->id, \'client_already_checkbox_yes\', true ),
);
return $fields;
}
我也尝试过其他一些类似的事情。我知道我缺少了从复选框中正确检索和评估值,并在知道值后将其粘贴到电子邮件中的内容。
我已经在这个结帐页面中添加了一些其他字段,这些字段将保存到meta并添加到交易电子邮件中,我不确定这里缺少了什么。
我对PHP不太感兴趣,所以我正在熟悉但不太舒服的领域中行走。