当我添加新产品或更新产品时,WooCommerce电子邮件通知所有客户

时间:2016-10-14 17:44:02

标签: php wordpress woocommerce

我尝试使用插件找到解决方案,但没有按照我的意愿工作,我想通过电子邮件通知我创建或更新产品时注册的所有客户。

我的功能

@Rule(
  key = "avoidSocketsApi",
  name = "The \"Sockets\" API should not be used",
  description = "...",
  priority = Priority.CRITICAL,
  tags = {"bug"})
public class AvoidSocketsApiRule extends IssuableSubscriptionVisitor {

2 个答案:

答案 0 :(得分:0)

请使用WordPress的以下操作挂钩获取自定义帖子类型:

add_action('save_post_product', 'your_function_name');
 add_action( 'publish_product', 'your_function_name');

function your_function_name( $post_id ) {
  // do code here
}

答案 1 :(得分:0)

// WP_User_Query arguments
$args = array (
    'role' => 'customer',
);

// The User Query
$user_query = new WP_User_Query( $args );

// The User Loop
if ( ! empty( $user_query->results ) ) {
    foreach ( $user_query->results as $user ) {

        $to = $user->user_email;
        // create mail temelate and send mail
        wp_mail( $to, $subject, $message, $headers = '', $attachments = array() );
    }
} else {
    // no users found
}