我在woocommerce的结帐页面中创建自定义文件以添加Reagent用户电子邮件:
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('ایمیل معرف'),
'placeholder' => __('ایمیل معرف خود را وارد کنید'),
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
return $checkout;
}
所以,如果Reagent用户电子邮件不存在,我现在想要收到错误。
我使用代码:
add_filter('my_custom_checkout_field', 'yourprefix_process_myaccount_address_fields' );
function yourprefix_process_myaccount_address_fields( $checkout ) {
$exists = email_exists($checkout);
if ( $exists )
echo "That E-mail is registered to user number" . $exists;
else
wc_add_notice( __( 'Email not exist', 'woocommerce' ), 'error' );
}
}
但代码不工作,没有得到任何错误...... 怎么办呢?