Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter lucatartarini

    (@lucatartarini)

    Good morning, thank you so much for your reply.
    Let me explain my problem better, as you can see from the attached code, on the cart page I have inserted a mail function that collects the user’s order. What I should do is insert in the “to” field a variable that collects the email addresses of the stores displayed in the map above, so that the customer’s order can be sent to all these stores. Is it possible to get this variable?

    <div id="sendlistform-wrapper">
    	
    	<h2>Invia la tua lista</h2>
    	<p>Compila il form sottostante e invia la tua lista ai gommisti individuati nella mappa. Da loro riceverai in risposta un preventivo.</p>
    
    
    <?php
    global $woocommerce;
    foreach ($woocommerce->cart->get_cart() as $item_id => $values) 
    {$string .= $values['quantity'].$values['data']->get_name().',';}
    
     
    
    
    
    ?>
    <form action="#" id="form" class="sendlistform"  method="post" name="form">
    <input type="text" name="nome" placeholder="Nome"><input type="text" name="email" placeholder="Email">
    <textarea name="message" placeholder="Il tuo messaggio..."></textarea>	
    <button type="submit" name="send_message_btn">Send</button>
    </form>
    <?php 
    	
    if(isset($_POST['send_message_btn']))
    {
    $from = $_POST['email'];
    $to = here the variable i should generate
    $subject = "Checking PHP mail";
    
    $headers = "From:" . $from;
    
    mail($to, $subject,$_POST['nome'].$_POST['message'].$string, $headers);
    
     echo '<div id="sent" class=" align-items-center">La tua lista è stata inviata.<br>Sarai presto ricontattato.<br><a href="https://www.lucatartarini.net/area-test/mastro-new-site">Torna alla Homepage</a></div>';
    }
    
    ?>
    
    </div>
    
    Thread Starter lucatartarini

    (@lucatartarini)

    Hello,

    Excuse me for returning to the topic, but if I understood correctly, by including the code you provided before the function that generates the email, I should be able to insert the $email variable in the to value of the function and intercept the emails from the stores that are within the search radius.

    <script>
    
    SELECT
        post_lat.meta_value AS lat,
        post_lng.meta_value AS lng,
        post_email.meta_value AS email,
        posts.ID,
        ( acos(
              cos( radians( '43.38104077335135' ) ) * cos( radians( post_lat.meta_value ) )
            * cos( radians( post_lng.meta_value ) - radians( '11.117474417224276'  ) )
                      + sin( radians( '43.38104077335135' ) ) * sin( radians( post_lat.meta_value ) ) )
        ) AS distance
    FROM wp_posts AS posts
        INNER JOIN wp_postmeta AS post_lat ON post_lat.post_id = posts.ID AND post_lat.meta_key = 'wpsl_lat'
        INNER JOIN wp_postmeta AS post_lng ON post_lng.post_id = posts.ID AND post_lng.meta_key = 'wpsl_lng'
        LEFT JOIN wp_postmeta AS post_email ON post_email.post_id = posts.ID AND post_email.meta_key = 'wpsl_email'
    WHERE posts.post_type = 'wpsl_stores' AND posts.post_status = 'publish'
    HAVING distance < 50 ORDER BY distance ASC LIMIT 0, 25
    
    </script>
    	
    <?php
    global $woocommerce;
    foreach ($woocommerce->cart->get_cart() as $item_id => $values) 
    {$string .='<li style="color:#fff; font-size:12px; padding:15px; border-bottom:dotted thin; "> <p  style="display:inline-block"><strong>'. $values['data']->get_name().'</strong></p><p> Numero pezzi:&nbsp'.$values['quantity'].'</p></li><br>';}
    
     
    
    
    
    ?>
    <form action="#" id="form" class="sendlistform"  method="post" name="form">
    <input type="text" name="nome" placeholder="Nome"><input type="text" name="email" placeholder="Email">
    <textarea name="message" placeholder="Il tuo messaggio..."></textarea>	
    <button type="submit" name="send_message_btn">Send</button>
    </form>
    <?php
    	
    if(isset($_POST['send_message_btn']))
    {
    $from = $_POST['email'];
    $to = $email;
    $subject = "Richiesta dal sito Mastro.it";
    $corpo = $_POST['message'];
    
    $header = "From:" . $from .  $_POST['nome'];
    

    This is the code I put in my file but it didn’t work.
    Could you tell me what I did wrong?

    Thank you so much for your availability

    Thread Starter lucatartarini

    (@lucatartarini)

    Thank you very much, but how do I then recall the value of the email field in a variable that can be inserted in a php mail function?

    This is the code I put in my theme’s function.php file:

    add_filter( 'wpsl_sql', 'custom_sql' );
    
    function custom_sql() {
        
        global $wpdb, $wpsl_settings;
        
        // Set a limit for the results and order them by distance.    
        if ( isset( $_GET['autoload'] ) && $_GET['autoload'] ) {
            $limit = '';
    
            if ( $wpsl_settings['autoload_limit'] ) {
                $limit = 'LIMIT %d';
            }
    
            $sql_sort = 'ORDER BY distance DESC '. $limit;
        } else {
            $sql_sort = 'HAVING distance < %d ORDER BY distance DESC LIMIT 0, %d';
        }
        
        // The default query that selects store location that fall within the selected radius. 
        $sql = "SELECT post_lat.meta_value AS lat,
                       post_lng.meta_value AS lng,
                       post_email.meta_value AS email,
                       posts.ID, 
                       ( %d * acos( cos( radians( %s ) ) * cos( radians( post_lat.meta_value ) ) * cos( radians( post_lng.meta_value ) - radians( %s ) ) + sin( radians( %s ) ) * sin( radians( post_lat.meta_value ) ) ) ) 
                    AS distance        
                  FROM $wpdb->posts AS posts 
            INNER JOIN $wpdb->postmeta AS post_lat ON post_lat.post_id = posts.ID AND post_lat.meta_key = 'wpsl_lat'
            INNER JOIN $wpdb->postmeta AS post_lng ON post_lng.post_id = posts.ID AND post_lng.meta_key = 'wpsl_lng'
            LEFT JOIN wp_postmeta AS post_email ON post_email.post_id = posts.ID AND post_email.meta_key = 'wpsl_email'
                 WHERE posts.post_type = 'wpsl_stores' AND posts.post_status = 'publish' $sql_sort";    
        
        return $sql;
    }

    while this is the code I have in the page template, I would like to recall the email value in the to variable to be inserted in the mail function

    if(isset($_POST['send_message_btn']))
    {
    $from = $_POST['email'];
    $to = ' ???????';
    $subject = "Richiesta dal sito Mastro.it";
    $corpo = $_POST['message'];
    
    $header = "From:" . $from .  $_POST['nome'];
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     
    // Create email headers
    $headers .= 'From: '.$from."\r\n".
        'Reply-To: '.$from."\r\n" .
        'X-Mailer: PHP/' . phpversion();
    $message = '<html><body style="background-image: url(https://www.lucatartarini.net/area-test/mastro-new-site/wp-content/uploads/2022/11/bck-mail.jpg);background-size:cover">';
    $message .= '<img src="https://www.lucatartarini.net/area-test/mastro-new-site/wp-content/uploads/2022/11/logo-1.png" width="250" /><p style="color:red; font-size:20px;background-color: rgba(0, 0, 0, 0.9);padding:10px 20px">Richiesta preventivo da &nbsp'.  $_POST['nome'].'</p>';
    $message .= '<p style="color:#fff;font-size:16px;background-color: rgba(0, 0, 0, 0.9);padding:10px 20px">'.$corpo.'</p>';
    $message .= '</body></html>';
    
    mail($to, $subject, $message, $headers);
    
     echo '<div id="sent" class=" align-items-center">La tua richiesta è stata inviata.<br>Sarai presto ricontattato.<br><a href="https://www.lucatartarini.net/area-test/mastro-new-site">Torna alla Homepage</a><a href="https://www.lucatartarini.net/area-test/mastro-new-site/officine-meccaniche/">Richiedi un altro preventivo</a></div>';
    }
    
    ?>

    Really thank you for your work, it is precious

    • This reply was modified 3 years, 5 months ago by lucatartarini.
    Thread Starter lucatartarini

    (@lucatartarini)

    Hi, I’m sorry but I have another question.
    My code will be executed inside a page template, after the user searches the wpsl map. At this point I should go to collect the emails of the stores included in the map, could you please give me an example of code that you would program to collect these maps?

    woocommerce has nothing to do with it, I just need to collect the emails relating to the stores searched by the user on the map

    Thank you very much, if needed I can also go and insert the page template code.

    Thread Starter lucatartarini

    (@lucatartarini)

    Thanks a lot for the answer.
    The last request really:
    if instead I started from a research in lugo, so I had a starting point, would it be possible to do?
    Let me explain better, if instead of the user’s geolocation, I forced the user to do a search, would it be possible at that point to collect the email addresses in a variable?

    Really thank you

    Thread Starter lucatartarini

    (@lucatartarini)

    Hi, thanks for the reply and sorry, I didn’t see it.
    The starting point must be that of the geolocated user.
    I’ll explain what the user experience should be:

    – create the cart (no problem);
    – it is geolocated and sees all the stores in its vicinity (ok, no problem)

    – send an email to all the stores identified.
    this will happen with a button that calls a php mail function. I should pass to this function a variable that contains the email addresses of the stores identified in the map. How can I include these addresses in a variable?

    in the previous messages you can see the code that is inside the page template

    Many thanks in advance

    Thread Starter lucatartarini

    (@lucatartarini)

    Good morning,
    I have not received a reply to my last message, I really need to solve this problem. Thank you in advance for your reply.

    Thread Starter lucatartarini

    (@lucatartarini)

    Thanks a lot for the answer,
    let me explain better, the user of my site creates a cart with woocommerce, then through the mail function of php I send this cart as a message. I would like this email to be sent to all the stores found on the map. I attack the code. I would like the email addresses of the map to be saved in the $to variable

    <?php
    global $woocommerce;
    foreach ($woocommerce->cart->get_cart() as $item_id => $values) 
    {$string .= $values['quantity'].$values['data']->get_name().',';}
    
     
    $to = /*here collect the email addresses of the map*/
    
    ?>
    <form action="#" id="form" method="post" name="form">
    <input type="text" name="email">
    <textarea name="message"></textarea>	
    <button type="submit" name="send_message_btn">Send</button>
    </form>
    <?php 
    	
    if(isset($_POST['send_message_btn']))
    {
    $from = $_POST['email'];
    
    $subject = "Checking PHP mail";
    
    $headers = "From:" . $from;
    
    mail($to, $subject,$_POST['message'].$string, $headers);
    
     echo 'Email Sent.';
    }
    
    ?>
Viewing 8 replies - 1 through 8 (of 8 total)