【发布时间】:2015-09-15 02:54:17
【问题描述】:
我想写一个函数来发送电子邮件。在邮件中,我想通过链接到 wordpress 产品页面的每个产品永久链接向客户发送他们订购的商品。
public function mailout($post_id = 106){
global $wpdb;
$mail = get_post_meta( $post_id, '_billing_email', true );
$product_name = $wpdb->get_results("SELECT order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = '$post_id' AND order_item_type = 'line_item'");
for($i = 0; $i < count($product_name); $i++){
$post_data[$i] = $product_name[$i]->order_item_name;
$get_postID[$i] = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_data[$i]' ");
$prod_url[$i] = get_post_permalink($get_postID[$i]);
}
$t= get_post_permalink(106);
// $to = $mail;
// $subject = 'Test';
// $message = 'Thank you for purchasing! Please help us in reviewing our products.';
// $headers[] = 'From: <donotreply@test.com>';
// wp_mail( $to, $subject, $message, $headers );
}
我设法获得正确的帖子 ID 并使用它来获取帖子永久链接,但它似乎返回给我的都是相同的“http://localhost/domainname”循环,所有这些都指向主页。
如何更改它并使其在电子邮件中显示一些示例格式,例如以下格式,其中永久链接位于产品名称旁边?或者如果您有任何其他方法可以缩短此代码
示例结果---(产品一:http://localhost/domainname)
【问题讨论】:
-
链接到您的本地主机不会让我们看到您的页面 xD 它是本地的 - 在您的机器上。
-
大声笑我已经可以做到了。开发阶段没有真正的数据可以在线获取实时服务器进行测试对我来说太 exp:D
标签: php wordpress email permalinks