1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Cross-sells |
4
|
|
|
* |
5
|
|
|
* This template can be overridden by copying it to yourtheme/woocommerce/cart/cross-sells.php. |
6
|
|
|
* |
7
|
|
|
* HOWEVER, on occasion WooCommerce will need to update template files and you |
8
|
|
|
* (the theme developer) will need to copy the new files to your theme to |
9
|
|
|
* maintain compatibility. We try to do this as little as possible, but it does |
10
|
|
|
* happen. When this occurs the version of the template file will be bumped and |
11
|
|
|
* the readme will list any important changes. |
12
|
|
|
* |
13
|
|
|
* @see https://docs.woothemes.com/document/template-structure/ |
14
|
|
|
* @author WooThemes |
15
|
|
|
* @package WooCommerce/Templates |
16
|
|
|
* @version 1.6.4 |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
20
|
|
|
exit; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
global $product, $woocommerce_loop; |
24
|
|
|
|
25
|
|
|
if ( ! $crosssells = WC()->cart->get_cross_sells() ) { |
26
|
|
|
return; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$args = array( |
30
|
|
|
'post_type' => 'product', |
31
|
|
|
'ignore_sticky_posts' => 1, |
32
|
|
|
'no_found_rows' => 1, |
33
|
|
|
'posts_per_page' => apply_filters( 'woocommerce_cross_sells_total', $posts_per_page ), |
34
|
|
|
'orderby' => $orderby, |
35
|
|
|
'post__in' => $crosssells, |
36
|
|
|
'meta_query' => WC()->query->get_meta_query() |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$products = new WP_Query( $args ); |
40
|
|
|
$woocommerce_loop['name'] = 'cross-sells'; |
41
|
|
|
$woocommerce_loop['columns'] = apply_filters( 'woocommerce_cross_sells_columns', $columns ); |
42
|
|
|
|
43
|
|
View Code Duplication |
if ( $products->have_posts() ) : ?> |
|
|
|
|
44
|
|
|
|
45
|
|
|
<div class="cross-sells"> |
46
|
|
|
|
47
|
|
|
<h2><?php _e( 'You may be interested in…', 'woocommerce' ) ?></h2> |
48
|
|
|
|
49
|
|
|
<?php woocommerce_product_loop_start(); ?> |
50
|
|
|
|
51
|
|
|
<?php while ( $products->have_posts() ) : $products->the_post(); ?> |
52
|
|
|
|
53
|
|
|
<?php wc_get_template_part( 'content', 'product' ); ?> |
54
|
|
|
|
55
|
|
|
<?php endwhile; // end of the loop. ?> |
56
|
|
|
|
57
|
|
|
<?php woocommerce_product_loop_end(); ?> |
58
|
|
|
|
59
|
|
|
</div> |
60
|
|
|
|
61
|
|
|
<?php endif; |
62
|
|
|
|
63
|
|
|
wp_reset_query(); |
64
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.