Change locale for WooCommerce email

To change WooCommerce email language you need to change the locale after order submit.

Using $_GET might be dirty, but works 🙂

Advertisements

WooCommerce email with custom total row

To add a custom total row to woocommerce email total section just hook into woocommerce_get_order_item_totals

Customise order total rows

add_filter('woocommerce_get_order_item_totals', 'my_woocommerce_get_order_item_totals', 10, 2);
function my_woocommerce_get_order_item_totals($total_rows, $order)
{
    $new_total_rows['cart_subtotal'] = $total_rows['cart_subtotal'];

    $new_total_rows['shipping'] = array(
        'label' => 'Slovak Parcel Service:',
        'value' => wc_price(3),
    );

    $gateway = wc_get_payment_gateway_by_order($order);
    if ('cod' == $gateway->id) {
        $new_total_rows['cod'] = array(
            'label' => 'Cash on delivery:',
            'value' => wc_price(1),
        );
    }

    $new_total_rows['order_total'] = $total_rows['order_total'];

    return $new_total_rows;
}

Customizing Monolog HTML formatter for email

Monolog can send emails when there’s an error, but in the provided HTML formatter I missed the REQUEST_URI and REMOTE_ADDR that triggered the error.

Some info is in the exceptions section, but not always and needs horizontal scrolling in the email client 🙂

So I just replicated the HtmlFormatter and added some lines (dirty hacks).

Added service class

 <service id="app.monolog.formatter.html" class="App\Service\MonologEmailFormatter" public="false" />

Change formatter service ID

# app/config/config_prod.yml
swift:
    type: swift_mailer
    from_email: "php@example.com"
    to_email: ["info@example.com"]
    subject: 'Error'
    level: error
    formatter: custom.monolog.formatter.html
    content_type: text/html

UPDATE: You might be interested in https://stefanoalletti.wordpress.com/2017/03/09/symfony-and-monolog-how-use-processor-in-your-project/