Woocommerce customize email checkout

This is my custom e-mail template which gets sent when a order is completed.

<?php
/**
 * Customer completed order email
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates/Emails
 * @version     1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?>

<?php do_action( 'woocommerce_email_header', $email_heading ); ?>

<p><?php printf( __( "Hi there. Your recent order on %s has been completed. Your order details are shown below for your reference:", 'woocommerce' ), get_option( 'blogname' ) ); ?></p>

<?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?>

<h2><?php echo __( 'Order:', 'woocommerce' ) . ' ' . $order->get_order_number(); ?></h2>

<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
    <thead>
        <tr>
            <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Product', 'woocommerce' ); ?></th>
            <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Quantity', 'woocommerce' ); ?></th>
            <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Price', 'woocommerce' ); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php echo $order->email_order_items_table( true, false, true ); ?>
    </tbody>
    <tfoot>
        <?php
            if ( $totals = $order->get_order_item_totals() ) {
                $i = 0;
                foreach ( $totals as $total ) {
                    $i++;
                    ?><tr>
                        <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
                        <td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
                    </tr><?php
                }
            }
        ?>
    </tfoot>
</table>

<?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text ); ?>

<?php do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text ); ?>

<h2><?php _e( 'Customer details', 'woocommerce' ); ?></h2>

<?php if ($order->billing_email) : ?>
    <p><strong><?php _e( 'Email:', 'woocommerce' ); ?></strong> <?php echo $order->billing_email; ?></p>
<?php endif; ?>
<?php if ($order->billing_phone) : ?>
    <p><strong><?php _e( 'Tel:', 'woocommerce' ); ?></strong> <?php echo $order->billing_phone; ?></p>
<?php endif; ?>

<?php wc_get_template( 'emails/email-addresses.php', array( 'order' => $order ) ); ?>

<?php do_action( 'woocommerce_email_footer' ); ?>

I want to insert PHP code there which connects to a database, does a select query which needs the article ID and how many of the article ID´s are purchased and then sends a new email with this data.
I tried it multiple times but at the end the mail always stopped working due to some PHP error which I couldn’t address without debugging opportunity.

Read More

As an example I tried:

<?php
$db = mysqli_connect("sqwffwq", "qwfqwf", "qwfqwf", "qwfwqf");
// here I have no clue how to receive the article ID´s and there amounts...
// I wasn't able to find the woocommerce function

$result = mysqli_query('SELECT * FROM etc. etc. ');
mail(results) //Should be no problem after I got the information
?>

Related posts

Leave a Reply

1 comment

  1. run this and see whats going on with each result. What you’ve failed to mention above is where you are adding this code, are you sure you have $order available?

        global $wpdb;
        $rere2 = substr( $order->get_order_number(), 4); 
        echo 'rere2='.$rere2.'<br>';
        $myrows = $wpdb->get_results( 'SELECT * FROM wp_woocommerce_order_items WHERE order_id = "'.$rere2.'"' );
        var_dump($myrows); 
        foreach ( $myrows as $myrow) { 
            //mail("etix@foxfiredev.net",$rere2,$myrow->order_item_id);
            $x=wp_mail( "etix@foxfiredev.net", $rere2 ,$myrow->order_item_id);
            echo $x.'<br>'; 
    
            $wpdb->update( 'wp_woocommerce_order_items', 
                  array('id'=>$variable), 
                  array('order_item_id'=>$myrow->order_item_id), 
            ); // change table name, column names and values to suit..
        } 
    
        exit;