Last active
August 30, 2017 22:12
-
-
Save Garconis/67bf0e2b887b155721f5398ef1504404 to your computer and use it in GitHub Desktop.
WooCommerce | Add Featured Products to bottom of certain WooCommerce emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// let's add a CUSTOM IMAGE SIZE that can be used for featured product images within the emails | |
add_action( 'after_setup_theme', 'add_email_featured_img_size' ); | |
function add_email_featured_img_size() { | |
add_image_size( 'email-featured-thumb', 130, 130, true ); // (cropped) | |
} | |
// add custom content to END OF EMAIL | |
add_action( 'woocommerce_email_footer', 'add_footer_content'); | |
function add_footer_content($email) { | |
// Adds Featured Products to bottom of certain emails | |
if ( $email->id == 'customer_processing_order' || $email->id == 'customer_completed_order' ) { | |
$meta_query = WC()->query->get_meta_query(); | |
$tax_query = WC()->query->get_tax_query(); | |
$tax_query[] = array( | |
'taxonomy' => 'product_visibility', | |
'field' => 'name', | |
'terms' => 'featured', | |
'operator' => 'IN', | |
); | |
$args = array( | |
'post_type' => 'product', | |
'post_status' => 'publish', | |
'ignore_sticky_posts' => 1, | |
'posts_per_page' => 3, | |
'orderby' => 'rand', | |
'order' => $atts['order'], | |
'meta_query' => $meta_query, | |
'tax_query' => $tax_query, | |
); | |
$loop = new WP_Query( $args ); | |
if ($loop->have_posts()) : | |
echo '<table id="featured-block" valign="top" cellpadding="0" cellspacing="0"><tr><td id="featured-block-title-wrapper" colspan="3"><table id="featured-block-title" border="0" cellpadding="0" cellspacing="0"><tr><td style="padding: 0;"><h2>You may also like…</h2></td></tr></table></td></tr><tr>'; | |
while ( $loop->have_posts() ) : $loop->the_post(); global $product; | |
echo'<td width="33%" valign="top">'; | |
if ( has_post_thumbnail( $loop->post->ID ) ) { | |
echo '<a href="' . get_permalink( $loop->post->ID ) . '" title="' . esc_attr( $loop->post->post_title ) . '">'; | |
echo get_the_post_thumbnail( $loop->post->ID, 'email-featured-thumb' ); | |
echo '</a>'; | |
} | |
echo '<h3>'; | |
echo '<a href="' . get_permalink( $loop->post->ID ) . '">'; | |
echo get_the_title( $loop->post->ID ); | |
echo '</a>'; | |
echo '</h3>'; | |
echo $product->get_price_html(); | |
//woocommerce_template_loop_add_to_cart( $loop->post, $product ); | |
echo'</td>'; | |
endwhile; | |
echo '</tr></table>'; | |
endif; | |
wp_reset_query(); | |
} // END Featured Products | |
} // END custom content at end of email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment