致命错误:在不在对象上下文中使用$ this - Dokan Wordpress插件

时间:2018-05-20 22:10:17

标签: wordpress email construct dokan

我在wordpress主题的function.php中使用此代码时收到此错误

看起来代码有两部分,我认为最后一部分必须在“构造函数”中,但我不知道该怎么做。

function order_email_include_saler_name( $order ) {
            $saler_id = dokan_get_seller_id_by_order( $order->id );
            $saler_info = get_user_by( 'id', $saler_id );

            ?>
            <table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">

                <tfoot>
                    <tr>
                        <th scope="row" style="text-align:left; width: 57%; border: 1px solid #eee; <?php  echo 'border-top-width: 4px;'; ?>"><?php _e( 'Saler Name:' ); ?></th>
                        <td style="text-align:left; border: 1px solid #eee; <?php  echo 'border-top-width: 4px;'; ?>"><?php echo $saler_info->display_name; ?></td>
                    </tr>
                </tfoot>
            </table>
            <?php
        }

这是构造函数部分:

add_action( 'woocommerce_email_after_order_table', array( $this, 'order_email_include_saler_name' ) );

请有人帮忙吗?我已阅读所有相同标题的帖子,但我不明白如何继续。我不是程序员,我不懂编码。

1 个答案:

答案 0 :(得分:0)

如果你的函数在你的functions.php中,而不是任何类的方法,只需使用钩子和函数名称挂钩如下:

add_action( 'woocommerce_email_after_order_table', 'order_email_include_saler_name', 10, 1 );