Skip to content

Instantly share code, notes, and snippets.

@vastolf
Last active March 26, 2020 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vastolf/42cc9359d6b616675d70659e6de6f7a4 to your computer and use it in GitHub Desktop.
Save vastolf/42cc9359d6b616675d70659e6de6f7a4 to your computer and use it in GitHub Desktop.
Vimeo for Woocommerce - Example customer-completed-order Email template
<?php
/**
* Customer completed order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-completed-order.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates/Emails
* @version 3.7.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/*
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<?php /* translators: %s: Site title */ ?>
<p><?php esc_html_e( 'Your payment to {Your Site Name Here} was successful! Use the details below to access your video purchase:', 'woocommerce' ); ?></p>
<?php
$orderItems = $order->get_items(); // All items in current cart order
// We need to loop through the products in the order as the user may have
// purchased multiple products
foreach($orderItems as $item_id => $item_data){
//
// Varibles related to product
//
$product = $item_data->get_product(); // Product
$product_id = $product->get_id(); // Product ID
$product_name = $product->get_name(); // Product Name (optional)
//
// Variables related to Vimeo video, available for use in your emails or anywhere else.
//
$video_id = get_post_meta($product_id, 'wc_vimeo_id', true); // Video ID (from Vimeo)
$video_password = get_post_meta($product_id, 'wc_vimeo_password', true); // Video Password, example below
$video_link = get_post_meta($product_id, 'wc_vimeo_link', true); // Video Link, exmaple below
$video_name = get_post_meta($product_id, 'wc_vimeo_name', true); // Video Name, example below
$video_uri = get_post_meta($product_id, 'wc_vimeo_uri', true); // Video URI
$video_description = get_post_meta($product_id, 'wc_vimeo_description', true); // Video Description, example below
$video_status = get_post_meta($product_id, 'wc_vimeo_status', true); // Video Status
if (isset($video_id) && strlen($video_id) > 0) { // if this product has a Vimeo ID set
?>
<div>
<!-- Video Name example -->
<h2><?php echo $video_name.' - Access Details'; ?></h2>
<table>
<tbody>
<!-- Video Link example -->
<?php if ($video_link && strlen($video_link) > 0) : ?>
<tr>
<td>Video Link</td>
<td><?php echo '<a href="'.$video_link.'">'.$video_link.'</a>'; ?></td>
</tr>
<?php endif; ?>
<!-- Video Password example -->
<?php if ($video_password && strlen($video_password) > 1) : ?>
<tr>
<td>Password / Access Code</td>
<td><code><?php print $video_password; ?></code></td>
</tr>
<?php endif; ?>
<!-- Video Description example -->
<?php if ($video_description && strlen($video_description) > 1) : ?>
<tr>
<td>Description</td>
<td><?php print $video_description; ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<?php
}
}
/*
* @hooked WC_Emails::order_details() Shows the order details table.
* @hooked WC_Structured_Data::generate_order_data() Generates structured data.
* @hooked WC_Structured_Data::output_structured_data() Outputs structured data.
* @since 2.5.0
*/
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
/*
* @hooked WC_Emails::order_meta() Shows order meta data.
*/
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
/*
* @hooked WC_Emails::customer_details() Shows customer details
* @hooked WC_Emails::email_address() Shows email address
*/
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
/**
* Show user-defined additional content - this is set in each email's settings.
*/
if ( $additional_content ) {
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
}
/*
* @hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment