【问题标题】:Woocommerce - get product author's email addressWoocommerce - 获取产品作者的电子邮件地址
【发布时间】:2018-01-08 10:27:12
【问题描述】:

我正在努力找出如何从 Woocommerce 获取产品作者的电子邮件地址。

我正在尝试这个:

<?php
global $post, $product;
$author_email = get_the_author_meta( 'email', $product->post->post_author );
return $author_email;
?>

但这似乎并不正确

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce author


    【解决方案1】:

    正确的元数据是user_email 而不是email

    <?php
    global $post, $product;
    $author_email = get_the_author_meta( 'user_email', $product->post->post_author );
    return $author_email;
    ?>
    

    Link to function description

    【讨论】:

      【解决方案2】:

      检查那个函数,把它粘贴到function.php上

      add_filter('post_type_link', 'add_author_id', 10, 4);
      
      function add_author_id($post_link, $post, $leavename, $sample) {
      if ('product' != get_post_type($post))
          return $post_link;
      $authordata = get_userdata($post->post_author);
      $author = $authordata->id;
      $post_link = str_replace('%author%', $author, $post_link);
      return $post_link;
       }
      

      【讨论】:

        猜你喜欢
        • 2022-07-27
        • 1970-01-01
        • 2011-09-24
        • 1970-01-01
        • 2018-04-14
        • 2012-07-05
        • 1970-01-01
        • 1970-01-01
        • 2017-04-21
        相关资源
        最近更新 更多