Displaying WooCommerce product images in DK PDF Template - php

I am trying to adapt this code to echoing out a fore each for the image gallary of the products on woocommerce into a pdf. If you could point me into the correct direction that would be great
<?php
/**
* dkpdf-index.php
* This template is used to display the content in the PDF
*
* Do not edit this template directly,
* copy this template and paste in your theme inside a directory named dkpdf
*/
?>
<html>
<head>
<link type="text/css" rel="stylesheet" href="<?php echo get_bloginfo( 'stylesheet_url' ); ?>" media="all" />
<?php
$wp_head = get_option( 'dkpdf_print_wp_head', '' );
if( $wp_head == 'on' ) {
wp_head();
}
?>
<style type="text/css">
body {
background:#fff;
font-size: 6pt;
}
/* fontawesome compatibility */
.fa {
font-family: fontawesome;
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
transform: translate(0, 0);
}
<?php
// get pdf custom css option
$css = get_option( 'dkpdf_pdf_custom_css', '' );
echo $css;
?>
</style>
</head>
<body>
<?php
global $post;
$pdf = get_query_var( 'pdf' );
$post_type = get_post_type( $pdf );
if( $pdf && $post_type == 'product' ) {
$title = get_the_title();
if( has_post_thumbnail( $post->ID ) ) {
$thumbnail = get_the_post_thumbnail( $post->ID, 'FULL' );
}
$description = get_the_excerpt();
$description2 = get_post($item['product_id'])->post_content;
$product = new WC_Product( $post->ID );
$link = get_the_permalink();
?>
<?php function yikes_custom_product_tabs_shortcode( $args ) {
global $post;
// Define our default values
$defaults = array(
'product_id' => $post->ID,
'tab_number' => 'all',
);
// Let the user-defined values override our defaults
$values = is_array( $args ) ? array_merge( $defaults, $args ) : $defaults;
// Make sure we have a product ID and that the product ID is for a product
if ( empty( $values['product_id'] ) || ! empty( $values['product_id'] ) && get_post_type( $values['product_id'] ) !== 'product' ) {
return;
}
// Fetch our tabs
$tabs = get_post_meta( $values['product_id'], 'yikes_woo_products_tabs', true );
// Get just the specified tab. (minus tab number by one so it starts at 0)
$tabs = absint( $values['tab_number'] ) < 1 ? $tabs : ( isset( $tabs[ absint( $values['tab_number'] ) - 1 ] ) ? array( $tabs[ absint( $values['tab_number'] ) - 1 ] ) : array() );
if ( empty( $tabs ) ) {
return;
}
// Debug statement to show all tab data. Feel free to remove.
// echo '<pre>'; var_dump( $tabs ); echo '</pre>';
$html = '';
// Loop through the tabs and display each one
foreach( $tabs as $tab ) {
$html .= '<tr>
<td style="padding-top:15px; padding-bottom:15px; text-align:center; line-height:2em; background:#f8f8f8;">';
$html .= '<h5>' . $tab['title'] . '</h5>';
$html .= '</td></tr>';
$html .= '<tr>
<td style="padding-top:20px; padding-bottom:20px; text-align:center; line-height:2em;">';
$html .= '<p style="font-size:10px;">' . $tab['content'] . '</p>';
$html .= '</td></tr>';
}
// Make sure to return your content, do not echo it.
return $html;
}
add_shortcode( 'custom_product_tabs', 'yikes_custom_product_tabs_shortcode' ); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="padding-top:20px; padding-bottom:20px;text-align:center; color:#fff;" class="bg-dark">
<h3 style="color:#fff;"><?php echo esc_attr( $title );?></h3>
</td>
</tr>
<tr>
<td style="padding-top:20px; padding-bottom:20px; text-align:center; line-height:2em;">
<p style="font-size:10px;"><?php echo $description;?></p>
</td>
</tr>
<tr>
<td style="padding-bottom:15px; text-align:center; line-height:2em; ">
<?php if( $thumbnail ) { echo $thumbnail; } ?>
</td>
</tr>
<tr>
<td style="padding-top:15px; padding-bottom:15px; text-align:center; line-height:2em; background:#f8f8f8;">
<h5>DESCRIPTION</p>
</td>
</tr>
<tr>
<td style="padding-top:20px; padding-bottom:20px; text-align:center; line-height:2em;">
<p style="font-size:10px;"><?php echo $description2;?> <?php echo wpautop( $post->post_content ); ?></p>
</td>
</tr>
<?php echo yikes_custom_product_tabs_shortcode('custom_product_tabs'); ?>
</table>
<?php }
?>
</body>
</html>

Related

Woocommerce get stock function in php

I need to add echo $product->get_stock_quantity() in following code to display it in pdf. Can you please help me to insert this $product->get_stock_quantity() into code bellow:
foreach ($order->get_items() as $item_id => $item) {
$product = wc_get_product($item->get_product_id());
$with_tax = $product->get_price_including_tax();
$without_tax = $product->get_price_excluding_tax();
$tax_amount = $with_tax - $without_tax;
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $item->get_product_id() ),'thumbnail' );
$css = ($item->get_quantity() > 1)?'color:red;':'';
?>
<tr><td><?php echo $product->get_sku();?></td><td><img width='60' src="<?php echo $image[0]; ?>"/></td><td style="text-align: center;font-family:DejaVu Sans, sans-serif;font-size:12px;"><?php echo $item->get_name();?></td><td style="text-align: center;"><img width='60' src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=<?php echo $product->get_sku();?>"/></td><td style="text-align: center; <?php echo $css;?>"><?php echo $item->get_quantity();?></td><td><?php echo wc_price( $with_tax );?> </td><td style="text-align: center;font-family:DejaVu Sans, sans-serif;">[]</td></tr>
Not succed to make myself.

Customize WooCommerce attribute table to two columns

I'm looking for some help getting customize the attribute table on WooCommerce.
<table>
<?php foreach (array_chunk($product_attributes, 2) as $product_attribute_key => $product_attribute) :{ ?>
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<?php foreach ($product_attribute as $value) :{ ?>
<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $value['label'] ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $value['value'] ); ?></td>
<?php } endforeach; ?>
</tr>
<?php } endforeach; ?>
</table>
I tried modify the above snippet in order to break line between Attribute Name and Attribute Value to display the attributes like it is in the below picture.
attributes
Is there any easy hook to get this work?
Thanks in Advance.
Create child-theme in case of theme update to not lose your settings.
Create in child-theme folders /woocommerce/single-product/ and copy from woocommerce/templates/single-product the file product-attributes.php.
Change:
defined( 'ABSPATH' ) || exit;
if ( ! $product_attributes ) {
return;
}
?>
<table class="woocommerce-product-attributes shop_attributes">
<?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></td>
</tr>
<?php endforeach; ?>
</table>
to
defined( 'ABSPATH' ) || exit;
if ( ! $product_attributes ) {
return;
}
$i = 0;
?>
<div class="woocommerce-product-attributes shop_attributes">
<?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
<div class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<div class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></div>
<div class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></div>
</div>
<?php
if ($i % 2 != 0){
echo '<div class="clear"></div>';
}
$i++;
endforeach; ?>
</div>
add CSS
/*2 Columnt style on product attributes*/
.woocommerce-product-attributes.shop_attributes .woocommerce-product-attributes-item {
float: left;
width: 50%;
margin-bottom: 8px;
padding-right:10px;
}

Woocommerce variation product image not showing in order emails

I'm using Woocommerce with Dynamic Gallery PRO. The images on the product pages work fine, and I also managed to display a product image in the emails sent to admin and customer. However, it's the main product image that's showing, not the variation image. As I understand the Gallery plugin uses the first image for the checkout page to display.
I already turned '$show_image' to true in email-order-details.php in Woocommerce.
The document of code I should edit (I think) is as following:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
foreach ( $items as $item_id => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item, $_product );
if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?>">
<td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap:break-word;"><?php
// Show title/image etc
**if ( $show_image ) {
echo apply_filters( 'woocommerce_order_item_thumbnail', '<div style="margin-bottom: 5px"><img src="' . ( $_product->get_image_id() ? current( wp_get_attachment_image_src( $_product->get_image_id(), 'thumbnail') ) : wc_placeholder_img_src() ) .'" alt="' . esc_attr__( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" /></div>', $item );
}**
// Product name
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
// SKU
if ( $show_sku && is_object( $_product ) && $_product->get_sku() ) {
echo ' (#' . $_product->get_sku() . ')';
}
// allow other plugins to add additional product information here
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );
// Variation
if ( ! empty( $item_meta->meta ) ) {
echo '<br/><small>' . nl2br( $item_meta->display( true, true, '_', "\n" ) ) . '</small>';
}
// File URLs
if ( $show_download_links ) {
$order->display_item_downloads( $item );
}
// allow other plugins to add additional product information here
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text );
?></td>
<td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ); ?></td>
<td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo $order->get_formatted_line_subtotal( $item ); ?></td>
</tr>
<?php
}
if ( $show_purchase_note && is_object( $_product ) && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) ) : ?>
<tr>
<td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
The file of Gallery PRO where it defines images is as following:
class WC_Dynamic_Gallery_Variations{
public static function wc_dgallery_change_variation() {
$product_id = (int) $_REQUEST['product_id'];
$variations = wp_unslash( $_REQUEST['variations'] );
ob_start();
if ( $variations == '' ) {
WC_Gallery_Display_Class::wc_dynamic_gallery_display($product_id);
} else {
WC_Gallery_Display_Class::get_gallery_variations($product_id, $variations);
}
$result = ob_get_clean();
echo json_encode($result);
die();
}
public static function change_image_in_cart_page( $product_image, $values, $cart_item_key ) {
if ( is_array( $values ) && isset( $values['variation_id'] ) && $values['variation_id'] > 0 ) {
$variation_id = $values['variation_id'];
$dgallery_ids = WC_Dynamic_Gallery_Functions::get_gallery_ids( $variation_id );
if ( is_array( $dgallery_ids ) && count( $dgallery_ids ) > 0 ) {
// Use first image from variation gallery
$img_id = (int) array_shift( $dgallery_ids );
$product_image = wp_get_attachment_image( $img_id, 'shop_thumbnail' );
}
} elseif ( isset( $values['product_id'] ) && $values['product_id'] > 0 ) {
$product_id = $values['product_id'];
// Don't change the image if product has featured image
if ( has_post_thumbnail( $product_id ) ) return $product_image;
$dgallery_ids = WC_Dynamic_Gallery_Functions::get_gallery_ids( $product_id );
if ( is_array( $dgallery_ids ) && count( $dgallery_ids ) > 0 ) {
// Use first image from variation gallery
$img_id = (int) array_shift( $dgallery_ids );
$product_image = wp_get_attachment_image( $img_id, 'shop_thumbnail' );
}
}
return $product_image;
}
public static function wc_dgallery_variation_save_gallery_ids() {
if ( isset( $_POST['variation_id'] ) && $_POST['variation_id'] > 0 && isset( $_POST['dgallery_ids'] ) ) {
$variation_id = trim( $_POST['variation_id'] );
$dgallery_ids = array_filter( explode( ',', trim( $_POST['dgallery_ids'] ) ) );
update_post_meta( $variation_id, '_product_image_gallery', implode( ',', $dgallery_ids ) );
}
die();
}
public static function add_gallery_variation( $loop, $variation_data, $variation ) {
$global_wc_dgallery_activate = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'activate' );
$actived_d_gallery = get_post_meta( $variation->post_parent, '_actived_d_gallery',true );
if ( $actived_d_gallery == '' && $global_wc_dgallery_activate != 'no' ) {
$actived_d_gallery = 1;
}
$default_show_variation = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'show_variation' );
$show_variation = get_post_meta($variation->post_parent, '_wc_dgallery_show_variation',true);
if ( $show_variation == '' ) {
$show_variation = $default_show_variation;
}
if ( $show_variation == 1 || $show_variation == 'yes' ) {
$show_variation = 1 ;
}
?>
<div class="variations_dgallery_activated_panel_container a3-metabox-panel-wrap a3-dynamic-metabox-panel-wrap" style="<?php if ( 1 != $actived_d_gallery ) { echo 'display: none;'; } ?> padding-left: 0px;">
<div class="a3-metabox-panel a3-metabox-wrapper">
<div id="variations_dgallery_panel" class="a3-metabox-items" style="<?php if ( 1 != $show_variation ) { echo 'display: none;'; } ?>">
<div class="dgallery_images_container dgallery_variation_images_container a3-metabox-options-panel">
<h4 style="margin:0;">
<?php echo __( 'Variation Gallery', 'woo_dgallery' ); ?>
<span class="a3_dg_variation_ajax_loader" style="display: none;"><img class="" src="<?php echo WOO_DYNAMIC_GALLERY_IMAGES_URL; ?>/ajax-loader.gif" /></span>
</h4>
<ul class="dgallery_images">
<?php
$variation_id = $variation->ID;
$dgallery_ids = WC_Dynamic_Gallery_Functions::get_gallery_ids( $variation_id );
if ( is_array( $dgallery_ids ) && count( $dgallery_ids ) > 0 ) {
foreach ( $dgallery_ids as $img_id ) {
$img_data = wp_get_attachment_image_src( $img_id, 'thumbnail' );
?>
<li class="image" data-attachment_id="<?php echo $img_id ; ?>">
<img class="image_item" src="<?php echo $img_data['0']; ?>" />
<ul class="actions">
<li><?php echo __( 'Delete image', 'woo_dgallery' ); ?></li>
</ul>
</li>
<?php
}
}
?>
</ul>
<input type="hidden" class="dgallery_ids" data-variation-id="<?php echo $variation_id; ?>" value="<?php if ( $dgallery_ids ) echo esc_attr( implode( ',', $dgallery_ids ) ); ?>" />
<p class="add_dgallery_images hide-if-no-js" style="margin: 10px 0px;">
<?php _e( 'Add variation gallery images', 'woo_dgallery' ); ?>
</p>
</div>
</div>
</div>
<?php
// Add an nonce field so we can check for it later.
//wp_nonce_field( 'a3_dynamic_variation_metabox_action', 'a3_dynamic_variation_metabox_nonce_field' );
?>
<div style="clear: both;"></div>
</div>
<?php
} }
Someone familiar with this issue? I'm not really a programmer but I learn a lot along the way.
Try this one near #$show_image, Its working for me.
Option 1:
echo $order->email_order_items_table( true, false, true, true, array(80,48) );
Option 2:
echo $_product->get_image();

WooCommerce E-mail Order - Products Alignment

I want to edit the email template for the WooCommerce Order, so that instead of the usual product per line table, I get 3 products per line (screenshot).
I don't know how to set a limit of 3 products per line though.
Only first 3 products show correctly.
Here is my snippet.
<?php
/**
* Email Order Items
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
foreach ( $items as $item_id => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item, $_product );
if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
?>
<td class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?>" style="text-align:center; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap:break-word;"><?php
// Show title/image etc
if ( $show_image ) {
echo apply_filters( 'woocommerce_order_item_thumbnail', '<div style="margin-bottom: 5px"><img src="' . ( $_product->get_image_id() ? current( wp_get_attachment_image_src( $_product->get_image_id(), 'thumbnail') ) : wc_placeholder_img_src() ) .'" alt="' . esc_attr__( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" /></div>', $item );
echo nl2br ("\n");
}
// Product name
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
echo nl2br ("\n");
//Product quantity
echo apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item );
echo nl2br (" piece(s)\n");
echo apply_filters( 'woocommerce_cart_item_weight', $_product->get_weight());
echo nl2br (" gr\n");
// SKU
if ( $show_sku && is_object( $_product ) && $_product->get_sku() ) {
echo nl2br ("\n");
echo ' (#' . $_product->get_sku() . ')';
}
// allow other plugins to add additional product information here
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );
?></td>
<?php
}
if ( $show_purchase_note && is_object( $_product ) && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) ) : ?>
<tr>
<td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); ?></td>
</tr>
<?php endif; ?>
I found a solution to it in case anyone is interested in aligning his products like this.
I inserted a counter $x to count the products in the end of the foreach loop and once it reaches the 3rd product, I have an if statement to change the table row and restart the counter.
Here is how the email looks like now: http://imgur.com/6q14Pes
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
$x = 0;
foreach ( $items as $item_id => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item, $_product );
$x += 1;
if( $x > 3 ){ ?>
<tr></tr>
<?php
$x = 0;
}
if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
?>
<td class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?>" style="text-align:center; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap:break-word;"><?php
// Show title/image etc
if ( $show_image ) {
echo apply_filters( 'woocommerce_order_item_thumbnail', '<div style="margin-bottom: 5px"><img src="' . ( $_product->get_image_id() ? current( wp_get_attachment_image_src( $_product->get_image_id(), 'thumbnail') ) : wc_placeholder_img_src() ) .'" alt="' . esc_attr__( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" /></div>', $item );
echo nl2br ("\n");
}
// Product name
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
echo nl2br ("\n");
//Product quantity
echo apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item );
echo nl2br (" piece(s)\n");
//Product weight
echo apply_filters( 'woocommerce_cart_item_weight', $_product->get_weight());
echo nl2br (" gr\n");
// SKU
if ( $show_sku && is_object( $_product ) && $_product->get_sku() ) {
echo nl2br ("\n");
echo ' (#' . $_product->get_sku() . ')';
}
// allow other plugins to add additional product information here
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );
?></td><?php
}
if ( $show_purchase_note && is_object( $_product ) && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) ) : ?>
<tr>
<td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); ?></td>
</tr>
<?php endif; ?>

Wordpress & Woocommerce add excerpt in order email

I have a little problem with Wordpress and Woocommerce I hope someone can help me.
When a person purchases receive an email with your data such as title, quantity, etc. ... I would also add the excerpt of the products near the quatity. The classic <? Php the_excerpt ();?> Does not work, does anyone know how to do?
The file is "email-order-items" in woocommerce\templates\emails
Here is the code:
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'orderby' => 'desc' );
$loop = new WP_Query( $args ); ?>
<?php
/**
* Email Order Items
*
* #author WooThemes
* #package WooCommerce/Templates/Emails
* #version 2.0.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $woocommerce;
foreach ($items as $item) :
// Get/prep product data
$_product = $order->get_product_from_item( $item );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] );
$image = ($show_image) ? '<img src="'. current(wp_get_attachment_image_src( get_post_thumbnail_id( $_product->id ), 'thumbnail')) .'" alt="Product Image" height="'.$image_size[1].'" width="'.$image_size[0].'" style="vertical-align:middle; margin-right: 10px;" />' : '';
?>
<tr>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php
// Show title/image etc
echo apply_filters( 'woocommerce_order_product_image', $image, $_product, $show_image);
// Product name
echo apply_filters( 'woocommerce_order_product_title', $item['name'], $_product );
// SKU
echo ($show_sku && $_product->get_sku()) ? ' - cod. articolo (#' . $_product->get_sku() . ')' : '';
// File URLs
if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) {
$download_file_urls = $order->get_downloadable_file_urls( $item['product_id'], $item['variation_id'], $item );
$i = 0;
foreach ( $download_file_urls as $file_url => $download_file_url ) {
echo '<br/><small>';
if ( count( $download_file_urls ) > 1 ) {
echo sprintf( __('Download %d:', 'woocommerce' ), $i + 1 );
} elseif ( $i == 0 )
echo __( 'Download:', 'woocommerce' );
echo ' ' . basename( $file_url ) . '</small>';
$i++;
}
}
// Variation
echo ($item_meta->meta) ? '<br/><small>' . nl2br( $item_meta->display( true, true ) ) . '</small>' : '';
?>
</td>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo $item['qty'] ;?> x <?php the_excerpt(); ?> </td>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo $order->get_formatted_line_subtotal( $item ); ?></td>
</tr>
<?php if ($show_purchase_note && $purchase_note = get_post_meta( $_product->id, '_purchase_note', true)) : ?>
<tr>
<td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo apply_filters('the_content', $purchase_note); ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
thank you very much
To get excerpt in order email try this code.
<?php
/**
* Email Order Items
*
* #author WooThemes
* #package WooCommerce/Templates/Emails
* #version 2.1.2
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
foreach ( $items as $item_id => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
/* To get product excerpt */
$product_data = get_post( $item['product_id'] );
$excerpt = strip_tags($product_data->post_excerpt);
echo $excerpt;
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $_product );
?>
<tr>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee; word-wrap:break-word;"><?php
// Show title/image etc
if ( $show_image ) {
echo apply_filters( 'woocommerce_order_item_thumbnail', '<img src="' . ( $_product->get_image_id() ? current( wp_get_attachment_image_src( $_product->get_image_id(), 'thumbnail') ) : wc_placeholder_img_src() ) .'" alt="' . __( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" />', $item );
}
// Product name
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item );
// SKU
if ( $show_sku && is_object( $_product ) && $_product->get_sku() ) {
echo ' (#' . $_product->get_sku() . ')';
}
// File URLs
if ( $show_download_links && is_object( $_product ) && $_product->exists() && $_product->is_downloadable() ) {
$download_files = $order->get_item_downloads( $item );
$i = 0;
foreach ( $download_files as $download_id => $file ) {
$i++;
if ( count( $download_files ) > 1 ) {
$prefix = sprintf( __( 'Download %d', 'woocommerce' ), $i );
} elseif ( $i == 1 ) {
$prefix = __( 'Download', 'woocommerce' );
}
echo '<br/><small>' . $prefix . ': ' . esc_html( $file['name'] ) . '</small>';
}
}
// Variation
if ( $item_meta->meta ) {
echo '<br/><small>' . nl2br( $item_meta->display( true, true ) ) . '</small>';
}
?></td>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo $item['qty'] ;?></td>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo $order->get_formatted_line_subtotal( $item ); ?></td>
</tr>
<?php if ( $show_purchase_note && is_object( $_product ) && $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) : ?>
<tr>
<td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo wpautop( do_shortcode( $purchase_note ) ); ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
I've used the following code to get the excerpt from Woocommerce order posts (delivery notes).
$post_id = $post_id_of_the_product;
$page_data = get_page( $post_id );
$excerpt = strip_tags($page_data->post_excerpt);

Categories