1

我使用simplecartjs在我的网站上制作了一个购物车,您可以在其中选择元素并将其发送到您的购物车...下一步,将是结帐过程,但出于商业原因,不会附加结帐过程,并带有一个简单的表格将询问姓名和电子邮件以及订单取货日期。现在必须将订单发送到将完成订单的电子邮件地址(在公司)。

问题:如何将购物车的内容发送到电子邮件正文或作为附件?

4

2 回答 2

2

这将向用户“电话和地址”添加电子邮件订单、补充字段,

在 CheckOut 期间检查用户是否已注册,如果没有将重定向到注册。

只有在成功发送电子邮件订单后才会清除购物车。

将向店主“shop@domain.com”和用户电子邮件发送 2 封电子邮件,以便他看到订单

成功下单后,需要为感谢部分创建一个新页面

simplecartjs:第 288 行左右在我的

me.emailCheckout = function() {    

    itemsString = "";
    for( var current in me.items ){ 
        var item = me.items[current];
        itemsString += item.name + " " + item.quantity + " " + item.price + "\n";
    }   

    var form = document.createElement("form");
    form.style.display = "none";
    form.method = "POST";
    form.action = "sendjs.php";
    form.acceptCharset = "utf-8";
    form.appendChild(me.createHiddenElement("jcitems", itemsString));
    form.appendChild(me.createHiddenElement("jctotal", me.total));
    document.body.appendChild(form);
    form.submit();
    document.body.removeChild(form); 
}

发送js.php

 <?php   require( dirname(__FILE__) . '/wp-load.php' );   
   /* cheking is user is logged in*/ 
   if ( is_user_logged_in() ) { 
    get_currentuserinfo(); /* getting user details*/

/* sending e-mail to the shop email */
        $to      = 'shop@domain.com';
        $subject = 'New Order';
        $jcitems =  " Name: " . $current_user->user_lastname .
                    " \n First Name: " . $current_user->user_firstname .
                    " \n Email: " . $current_user->user_email .
                    " \n Phone: " . $current_user->phone .
                    " \n Adress: " . $current_user->adress ;
        $headers = 'From: shop@domain.com' . "\r\n" .
                   'Reply-To: shop@domain.com' . "\r\n" .
                   'X-Mailer: PHP/' . phpversion();
        mail($to, $subject, $jcitems, $headers);

/* sending e-mail with the order to the users email*/        

        $to      = $current_user->user_email;
        $subject = 'Order copy from Domain';
        $jcitems =  "Thank you for you order. Below you have your ordered products".
                    " \n ORDER: \n\n " . $_POST['jcitems'] . "Total: " . $_POST['jctotal'] . " USD" .
                    "\n\n http://www.domain.com \nshop@domain.com";
        $headers = 'From: shop@domain.com' . "\r\n" .
                   'Reply-To: shop@domain.com' . "\r\n" .
                   'X-Mailer: PHP/' . phpversion();
        mail($to, $subject, $jcitems, $headers);
        /*Clearing the cart info after succesfull order is made*/
        setcookie ("simpleCart", "", time() - 3600);
        /*redirecting user to Thank you page from Wordpress*/
    Header('Location: http://www.domain.com/thank_you/');  } 

    else { /*sending user to register*/
        header( 'Location: http://www.domain.com/wp-login.php?action=register' ) ; exit; }   ?>

您将需要用于 wordpress 的 Register Plus 插件以将额外的 2 个字段添加到用户“电话和地址”
,请务必检查
添加注册字段
添加配置文件字段
必填

于 2011-07-14T13:45:32.497 回答
1

您应该向 simplecartjs 添加新的结帐方法:

me.emailCheckout = function() {    

    itemsString = "";
    for( var current in me.items ){ 
        var item = me.items[current];
        itemsString += item.name + " " + item.quantity + " " + item.price + "\n";
    }   

    var form = document.createElement("form");
    form.style.display = "none";
    form.method = "POST";
    form.action = "sendjs.php";
    form.acceptCharset = "utf-8";
    form.appendChild(me.createHiddenElement("jcitems", itemsString));
    form.appendChild(me.createHiddenElement("jctotal", me.total));
    document.body.appendChild(form);
    form.submit();
    document.body.removeChild(form);
}

这将创建新的表单元素并将购物车数据提交到 sendjs.php。通过在 simplecart 选项中设置 me.checkoutTo = 'Email' 来启用此结帐方法。

现在创建一个新的 sendjs.php 文件:

<?php
    $to      = 'you@example.com';
    $subject = 'the subject';
    $jcitems = $_POST['jcitems'];
    $headers = 'From: webmaster@example.com' . "\r\n" .
               'Reply-To: webmaster@example.com' . "\r\n" .
               'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $jcitems, $headers);
    Header('Location: thankyou.html');
?>

这将发送电子邮件并重定向到您也应该创建的thankyou.html 页面。

于 2010-02-19T13:08:17.360 回答