Wordpress:在注册通知

时间:2017-10-12 09:27:58

标签: php wordpress output customization

在WordPress中,我为新用户提供自定义注册网站。注册后,有一个可选的复选框来订阅我们的新闻通讯。据我了解,它将复选框的值添加到user_meta表中(整个事情已由印度的一家公司编码,我非常希望不再涉及,因为他们延迟了他们的工作时间和时间再一次,毕竟没有做好工作。)

我孩子主题的functions.php中的相应代码片段如下所示:

<?php echo '<div class="form-row form-row-wide">
<input type="checkbox" name="inter_offers" value="yes"> '; _e('I would like to subscribe to the Kurth Electronic newsletter.','kurth-child'); echo '<br></div>'; 
return $fields; ?>

add_action('woocommerce_created_customer','adding_extra_reg_fields');    
function adding_extra_reg_fields($user_id) {
extract($_POST);
update_user_meta($user_id, 'billing_inter_offers',$inter_offers);
} ?>

(我遗漏了与此问题无关的内容。)

现在,此值在内部保存,但不会显示给我。我希望在用户完成注册时显示WordPress生成的电子邮件或通知中的值,以便我们可以在有人选择订阅时事通讯时手动将它们添加到我们的时事通讯列表中。问题是我对PHP的知识有限,我不知道从哪里开始。

我还应该注意,这不是通过标准的WorPress注册表单完成的,而是通过WooCommerce注册表单(我出于安全原因禁用了标准的WordPress注册)。

我尝试在新用户完成注册时使用“Better Notifications”插件(https://wordpress.org/plugins/bnfw/)进行自定义通知,但它忽略了我添加到自定义通知正文以显示user_meta数据的任何php代码。

任何帮助都将不胜感激。

3 个答案:

答案 0 :(得分:0)

Because the registration is done via woocomerce you may have to look for a notification PlugIN that works with woocomerce, the one you have may just work properly with wordpress core version!

You also could generate a mail via php in the function, so that you get a message with the user mail adress, but i think without php knowledge it is not that easy to use the built in php mailer... (You may need an api there!)

But wouldn't it be better to automatically sign them into your newsletter software? For example for Mailchimp or other systems like that there are quite good wordpress plugins!

You may also be able to include the forms of these PlugIns in your registration form, but without a closer look at this woocomerce registration i can't tell for sure!

答案 1 :(得分:0)

I think this will do the trick, it will notify you every time a new user is created and also tell you if they subscribed or not.

function new_customer_registered_send_email_admin($user_login, $user_email) {
    ob_start();
    do_action('woocommerce_email_header', 'New customer registered');
    $email_header = ob_get_clean();
    ob_start();
    do_action('woocommerce_email_footer');
    $email_footer = ob_get_clean();

    $user = get_user_by( 'email', $user_email );
    $subscribed = get_user_meta( $user->ID, 'billing_inter_offers', true );

    woocommerce_mail(
        get_bloginfo('admin_email'),
        get_bloginfo('name').' - New customer registered',
        $email_header.'<p>The user '.esc_html( $user_login ).' created an account ' . ( $subscribed ? ' and subscribed to the newsletter.' : '.' ) . '<br>Email:'.esc_html( $user_email ).'</p>'.$email_footer
    );
}

add_action('new_customer_registered', 'new_customer_registered_send_email_admin', 10, 2);

答案 2 :(得分:0)

我最终使用插件amr users生成了一个将特定元数据标签设置为特定值的所有用户的用户列表(在我的情况下,如果他们想接收新闻稿-以前的开发人员从不会打扰使数据真正可读,而无需付出额外的努力)。使用起来有点笨拙,不是我最初打算的,但是它完成了工作。