Guest User

Untitled

a guest
May 27th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. add_action( 'woocommerce_order_details_after_order_table', 'post_sale_cross_sell' );
  2. function post_sale_cross_sell( $order ) {
  3. $cross_sells = array();
  4. $in_order = array();
  5.  
  6. foreach ( $order->get_items() as $item ) {
  7. $product_id = $order->get_item( $item )->get_product_id();
  8. $product = wc_get_product( $product_id );
  9. $cross_sells = array_merge( $product->get_cross_sell_ids(), $cross_sells );
  10. $in_order[] = $product_id;
  11. }
  12.  
  13. $cross_sells = array_diff( $cross_sells, $in_order );
  14. $cross_sells = apply_filters( 'woocommerce_cart_crosssell_ids', wp_parse_id_list( $cross_sells ) );
  15. ?>
  16.  
  17. <section class="related products post_sale">
  18.  
  19. <h2><?php esc_html_e( 'You might be interested in...', 'domain' ); ?></h2>
  20.  
  21. <p><?php esc_html_e( 'People who purchased the same products you bought usually also buy the following ones. Care to take a look?', 'woocommerce' ); ?></p>
  22.  
  23. <?php woocommerce_product_loop_start(); ?>
  24.  
  25. <?php foreach ( $cross_sells as $product_id ) : ?>
  26.  
  27. <?php
  28. $post_object = get_post( $product_id );
  29.  
  30. setup_postdata( $GLOBALS['post'] =& $post_object );
  31.  
  32. wc_get_template_part( 'content', 'product' ); ?>
  33.  
  34. <?php endforeach; ?>
  35.  
  36. <?php woocommerce_product_loop_end(); ?>
  37.  
  38. </section>
  39. <?php
  40. }
Add Comment
Please, Sign In to add comment