【发布时间】:2013-08-26 14:38:04
【问题描述】:
我正在使用一个函数来执行一个发送带有附件的电子邮件的代码。 此函数与来自 woocommerce 的过滤器挂钩。
我想重建这个函数来执行来自外部 php 文件的代码。 这在 Wordpress 中可行吗?
我想从外部脚本执行它的原因是因为我想要更多的功能,电子邮件的发件人和附件是从会话中生成的。
在我的子主题的function.php-
function send_invoice ()
{
$attachments = array( WP_CONTENT_DIR . '/themes/mytheme/invoices/invoice.pdf' );
wp_mail( 'targetmail@domain.com', 'Attachment test', 'The message', 'header', $attachments);
}
add_filter( 'woocommerce_email_attachments', 'send_invoice' );
有没有办法从我的functions.php中执行一个php文件?
进一步阐述: 我正在尝试将以前的脚本转换为: 函数.php
function execute_send_invoice () {
send_invoice();
}
add_filter( 'woocommerce_email_attachments', 'execute_send_invoice' );
然后是 send_invoice() 的代码;我的functions.php之外的某个地方,例如,位于我的模板目录中的myscript.php中。
【问题讨论】:
-
如果包含文件,无论是否包含wordpress,都可以正常调用函数
-
所以我不必链接新的php文件,如果我只是在那里编写我的函数,我可以在我的functions.php中调用它吗?顺便说一句,您能定义“包含”吗?我必须手动链接它,还是在我的主题目录中包含一个文件?
-
查看我的答案以获得解释。使用 wordpress,当主题处于活动状态时,
functions.php会自动包含在内。
标签: php wordpress woocommerce