Skip to content

Instantly share code, notes, and snippets.

@melissajclark
Last active May 26, 2019 16:34
Show Gist options
  • Save melissajclark/0c216cd06352bb94184e48f90f24976a to your computer and use it in GitHub Desktop.
Save melissajclark/0c216cd06352bb94184e48f90f24976a to your computer and use it in GitHub Desktop.
Customize WooCommerce email to show membership card
<?php
/**
*
* Template: customer-completed-order.php
*
* Customize the email to include a member card.
*
* @link https://businessbloomer.com/woocommerce-check-product-id-order/
*
*/
function client_theme_woocommerce_email_member_card($order) {
$client_order_day_month = date("F d");
$client_order_year = date("Y");
$client_order_renewal_year = $client_order_year + 1;
$client_address_line_1 = get_option('options_address_line_1');
$client_address_line_2 = get_option('options_address_line_2');
$client_address_line_3 = get_option('options_address_line_3');
$client_phone_number = get_option('options_phone_number');
// Check if this order includes the membership product
$client_order = new WC_Order( $order->get_id() );
$client_items = $client_order->get_items();
foreach ( $client_items as $client_item ) {
$client_product_id = $client_item['product_id'];
if ( $client_product_id == 282 ) { ?>
<p><strong><?php echo esc_html_e('Cut out the card below and keep it in your wallet to claim benefits at participating bookstores and theatres.', 'client-name'); ?></strong></p>
<table style="width:100%; border: 3px solid #e5e5e5; margin-bottom:40px; font-size:14px;">
<tbody>
<tr>
<td>
<h2><?php echo esc_html_e('Membership Card', 'client-name'); ?></h2>
<?php
if ( !empty( $client_address_line_1 ) ) {
echo '<span style="display:block;">' . esc_html( $client_address_line_1 ) . '</span>';
}
if ( !empty( $client_address_line_2 ) || !empty( $client_address_line_2 ) ) {
echo '<span style="display:block;">' . esc_html( $client_address_line_2 ) . '<span> ' . esc_html( $client_address_line_3 ) . '</span></span>';
}
if ( !empty( $client_phone_number ) ) {
echo '<span style="display:block;">' . esc_html( $client_phone_number ) . '</span>';
}
echo '<a href="' . esc_url( site_url() ) . '">' . esc_html( site_url() ) . '</a>';
?>
</td>
<td><img src="<?php echo get_template_directory_uri(); ?>/assets/img/logo.png" width="200px" alt="<?php echo esc_html_e('Client Name', 'client-name'); ?>"></td>
</tr>
<tr>
<td style="text-transform:capitalize;"><strong><?php echo esc_html_e('Name:','client-name'); ?></strong> <?php echo get_post_meta($order->get_id(), '_billing_first_name', true) ?> <?php echo get_post_meta($order->get_id(), '_billing_last_name', true) ?></td>
</tr>
<tr>
<td style="padding-top:0;"><strong><?php echo esc_html_e('Date to Renew:','client-name'); ?></strong> <?php echo $client_order_day_month; ?><?php echo ', ' . $client_order_renewal_year; ?>
</td>
</tr>
</tbody>
</table>
<?php } // if is membership product ( ID = 282 )
} // foreach product
} // function client_theme_woocommerce_email_member_card
add_action('woocommerce_email_order_details', 'client_theme_woocommerce_email_member_card', 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment