Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save plugin-republic/4d095d574e5f675475e8ec5d5975a1ea to your computer and use it in GitHub Desktop.
Save plugin-republic/4d095d574e5f675475e8ec5d5975a1ea to your computer and use it in GitHub Desktop.
Example function getting field data from the order
<?php
/**
* Optionally attach uploaded images to the order email
*/
function pewc_attach_images_to_email( $attachments, $id, $order ) {
if( ( $id == 'new_order' || $id == 'customer_on_hold_order' ) && get_option( 'pewc_email_images', 'no' ) == 'yes' ) {
// Find any attachments
$order_items = $order->get_items( 'line_item' );
if( $order_items ) {
foreach( $order_items as $order_item ) {
$product_extras = $order_item->get_meta( 'product_extras' );
if( ! empty( $product_extras['groups'] ) ) {
foreach( $product_extras['groups'] as $group ) {
foreach( $group as $item_id=>$item ) {
if( ! empty( $item['file'] ) ) {
$attachments[] = $item['file'];
}
}
}
}
}
}
}
return $attachments;
}
add_filter( 'woocommerce_email_attachments', 'pewc_attach_images_to_email', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment