Advertisement
Fany_VanDaal

Podobné produkty v emailu objednávky

Oct 11th, 2023
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. // přidání relativních produktů do emailu o zpracovávání objednávky
  2. add_action( 'woocommerce_email_after_order_table', 'vandaal_add_product_grid_specific_email', 20, 4 );
  3.    
  4. function vandaal_add_product_grid_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
  5.    
  6.    if ( $email->id == 'customer_processing_order' ) {
  7.        
  8.       $related = array();
  9.       foreach ( $order->get_items() as $item_id => $item ) {        
  10.          $related = array_merge( wc_get_related_products( $item->get_product_id() ), $related );
  11.       }
  12.       if ( ! $related ) return;
  13.       shuffle( $related );
  14.       $related = array_unique( $related );
  15.        
  16.       echo '<h2>Naše další zajímavé produkty</h2>';
  17.        
  18.       $html = '';
  19.       $col = 1;
  20.       $cols = 3;
  21.       $limit = 6;
  22.       $html .= '<div><table style="table-layout:fixed;width:100%;"><tbody>';    
  23.       foreach ( array_slice( $related, 0, $limit ) as $product_id ) {
  24.          $product = wc_get_product( $product_id );
  25.          $html .= ( $col + $cols - 1 ) % $cols === 0 ? '<tr>' : '';
  26.          $html .= '<td style="text-align:center;vertical-align:bottom">';
  27.          $html .= $product->get_image();
  28.          $html .= '<h3 style="text-align:center">' . $product->get_title() . '</h3>';
  29.          $html .= '<p>' . $product->get_price_html() . '</p>';
  30.          $html .= '<p><a href="' . get_permalink( $product_id ) . '">' . __( 'Read more', 'woocommerce' ) . '</a></p></td>';
  31.          $html .= $col % $cols === 0 ? '</tr>' : '';
  32.          $col++;
  33.       }
  34.       $html .= '</tbody></table></div>';
  35.        
  36.       echo $html;
  37.        
  38.    }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement