OSDN Git Service

WordPressテンプレート使用ショップデモデータ追加。
[magic3/magic3.git] / templates / shop-isle / inc / sections / shop_isle_products_slider_section.php
1 <?php
2 /**
3  * Front page Product Slider Section
4  *
5  * @package WordPress
6  * @subpackage Shop Isle
7  */
8
9 $shop_isle_products_slider_hide = get_theme_mod( 'shop_isle_products_slider_hide', false );
10 if ( ! empty( $shop_isle_products_slider_hide ) && (bool) $shop_isle_products_slider_hide === true ) {
11         return;
12 }
13
14 echo '<section class="home-product-slider">';
15
16
17 echo '<div class="container">';
18
19
20 if ( current_user_can( 'edit_theme_options' ) ) {
21         $shop_isle_products_slider_title = get_theme_mod( 'shop_isle_products_slider_title', __( 'Exclusive products', 'shop-isle' ) );
22         if ( ! class_exists( 'WC_Product' ) ) {
23                 $shop_isle_products_slider_subtitle = get_theme_mod( 'shop_isle_products_slider_subtitle', __( 'For this section to work, you first need to install the WooCommerce plugin , create some products, and select a product category in Customize -> Frontpage sections -> Products slider section', 'shop-isle' ) );
24         } else {
25                 $shop_isle_products_slider_subtitle = get_theme_mod( 'shop_isle_products_slider_subtitle' );
26         }
27 } else {
28         $shop_isle_products_slider_title    = get_theme_mod( 'shop_isle_products_slider_title' );
29         $shop_isle_products_slider_subtitle = get_theme_mod( 'shop_isle_products_slider_subtitle' );
30 }
31
32
33 if ( ! empty( $shop_isle_products_slider_title ) || ! empty( $shop_isle_products_slider_subtitle ) ) :
34         echo '<div class="row">';
35         echo '<div class="col-sm-6 col-sm-offset-3">';
36         if ( ! empty( $shop_isle_products_slider_title ) ) :
37                 echo '<h2 class="module-title font-alt home-prod-title">' . $shop_isle_products_slider_title . '</h2>';
38         endif;
39         if ( ! empty( $shop_isle_products_slider_subtitle ) ) :
40                 echo '<div class="module-subtitle font-serif home-prod-subtitle">' . $shop_isle_products_slider_subtitle . '</div>';
41         endif;
42         echo '</div>';
43         echo '</div><!-- .row -->';
44 endif;
45
46 $shop_isle_products_slider_category = get_theme_mod( 'shop_isle_products_slider_category' );
47
48
49 $tax_query_item  = array();
50 $meta_query_item = array();
51
52 if ( taxonomy_exists( 'product_visibility' ) ) {
53         $tax_query_item = array(
54                 array(
55                         'taxonomy' => 'product_visibility',
56                         'field'    => 'term_id',
57                         'terms'    => 'exclude-from-catalog',
58                         'operator' => 'NOT IN',
59                 ),
60         );
61 } else {
62         $meta_query_item = array(
63                 'key'     => '_visibility',
64                 'value'   => 'hidden',
65                 'compare' => '!=',
66         );
67 }
68
69 $shop_isle_products_slider_args = array(
70         'post_type'      => 'product',
71         'posts_per_page' => 10,
72 );
73
74 if ( ! empty( $shop_isle_products_slider_category ) && ( $shop_isle_products_slider_category != '-' ) ) {
75         $shop_isle_products_slider_args['tax_query'] = array(
76                 array(
77                         'taxonomy' => 'product_cat',
78                         'field'    => 'term_id',
79                         'terms'    => $shop_isle_products_slider_category,
80                 ),
81         );
82 }
83
84 if ( ! empty( $tax_query_item ) ) {
85         $shop_isle_products_slider_args['tax_query']['relation'] = 'AND';
86         $shop_isle_products_slider_args['tax_query']             = array_merge( $shop_isle_products_slider_args['tax_query'], $tax_query_item );
87 }
88
89 if ( ! empty( $meta_query_item ) ) {
90         $shop_isle_products_slider_args['meta_query'] = $meta_query_item;
91 }
92
93
94
95 if ( ! empty( $shop_isle_products_slider_category ) && ( $shop_isle_products_slider_category != '-' ) ) :
96
97         $shop_isle_products_slider_loop = new WP_Query( $shop_isle_products_slider_args );
98
99         if ( $shop_isle_products_slider_loop->have_posts() ) :
100
101                 $rtl_slider = apply_filters( 'shop_isle_products_slider_section_rtl', 'false' );
102                 $number_of_items = apply_filters( 'shop_isle_products_slider_section_items', 5 );
103                 $pagination = apply_filters( 'shop_isle_products_slider_section_pagination', 'false' );
104                 $navigation = apply_filters( 'shop_isle_products_slider_section_navigation', 'false' );
105
106                 echo '<div class="row">';
107
108                 echo '<div class="owl-carousel text-center" data-items="' . esc_attr( $number_of_items ) . '" data-pagination="' . esc_attr( $pagination ) . '" data-navigation="' . esc_attr( $navigation ) . '" data-rtl="' . esc_attr( $rtl_slider ) . '" >';
109
110                 while ( $shop_isle_products_slider_loop->have_posts() ) :
111
112                         $shop_isle_products_slider_loop->the_post();
113                         global $product;
114                         echo '<div class="owl-item">';
115                         echo '<div class="col-sm-12">';
116                         echo '<div class="ex-product">';
117                         if ( function_exists( 'woocommerce_get_product_thumbnail' ) ) :
118                                 echo '<a href="' . esc_url( get_permalink() ) . '">' . woocommerce_get_product_thumbnail() . '</a>';
119                         endif;
120                         echo '<h4 class="shop-item-title font-alt"><a href="' . esc_url( get_permalink() ) . '">' . get_the_title() . '</a></h4>';
121                         $rating_html = '';
122                         if ( function_exists( 'method_exists' ) && ( function_exists( 'wc_get_rating_html' ) ) && method_exists( $product, 'get_average_rating' ) ) {
123                                 $shop_isle_avg = $product->get_average_rating();
124                                 if ( ! empty( $shop_isle_avg ) ) {
125                                         $rating_html = wc_get_rating_html( $shop_isle_avg );
126                                 }
127                         } elseif ( function_exists( 'method_exists' ) && method_exists( $product, 'get_rating_html' ) && method_exists( $product, 'get_average_rating' ) ) {
128                                 $shop_isle_avg = $product->get_average_rating();
129                                 if ( ! empty( $shop_isle_avg ) ) {
130                                         $rating_html = $product->get_rating_html( $shop_isle_avg );
131                                 }
132                         }
133                         if ( ! empty( $rating_html ) && get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {
134                                 echo '<div class="product-rating-home">' . $rating_html . '</div>';
135                         }
136                         if ( function_exists( 'method_exists' ) && method_exists( $product, 'is_on_sale' ) ) {
137                                 if ( $product->is_on_sale() ) {
138                                         if ( function_exists( 'woocommerce_show_product_sale_flash' ) ) {
139                                                 woocommerce_show_product_sale_flash();
140                                         }
141                                 }
142                         }
143                         if ( function_exists( 'method_exists' ) && method_exists( $product, 'managing_stock' ) && method_exists( $product, 'is_in_stock' ) ) {
144                                 if ( ! $product->managing_stock() && ! $product->is_in_stock() ) {
145                                         echo '<span class="onsale stock out-of-stock">' . esc_html__( 'Out of Stock', 'shop-isle' ) . '</span>';
146                                 }
147                         }
148                         $shop_isle_price = '';
149                         if ( function_exists( 'method_exists' ) && method_exists( $product, 'get_price_html' ) ) {
150                                 $shop_isle_price = $product->get_price_html();
151                         }
152                         if ( ! empty( $shop_isle_price ) ) {
153                                 echo wp_kses_post( $shop_isle_price );
154                         }
155                         echo '</div>';
156                         echo '</div>';
157                         echo '</div>';
158
159                 endwhile;
160
161                 wp_reset_postdata();
162                 echo '</div>';
163
164                 echo '</div>';
165
166         endif;
167
168 else :
169
170         $shop_isle_products_slider_loop = new WP_Query( $shop_isle_products_slider_args );
171
172         if ( $shop_isle_products_slider_loop->have_posts() ) :
173
174                 $rtl_slider = apply_filters( 'shop_isle_products_slider_section_rtl', 'false' );
175                 $number_of_items = apply_filters( 'shop_isle_products_slider_section_items', 5 );
176                 $pagination = apply_filters( 'shop_isle_products_slider_section_pagination', 'false' );
177                 $navigation = apply_filters( 'shop_isle_products_slider_section_navigation', 'false' );
178                 echo '<div class="row">';
179
180                 echo '<div class="owl-carousel text-center" data-items="' . esc_attr( $number_of_items ) . '" data-pagination="' . esc_attr( $pagination ) . '" data-navigation="' . esc_attr( $navigation ) . '" data-rtl="' . esc_attr( $rtl_slider ) . '">';
181
182                 while ( $shop_isle_products_slider_loop->have_posts() ) :
183
184                         $shop_isle_products_slider_loop->the_post();
185                         global $product;
186                         echo '<div class="owl-item">';
187                         echo '<div class="col-sm-12">';
188                         echo '<div class="ex-product">';
189                         if ( function_exists( 'woocommerce_get_product_thumbnail' ) ) :
190                                 echo '<a href="' . esc_url( get_permalink() ) . '">' . woocommerce_get_product_thumbnail() . '</a>';
191                         endif;
192                         echo '<h4 class="shop-item-title font-alt"><a href="' . esc_url( get_permalink() ) . '">' . get_the_title() . '</a></h4>';
193
194                         $rating_html = '';
195                         if ( function_exists( 'method_exists' ) && ( function_exists( 'wc_get_rating_html' ) ) && method_exists( $product, 'get_average_rating' ) ) {
196                                 $shop_isle_avg = $product->get_average_rating();
197                                 if ( ! empty( $shop_isle_avg ) ) {
198                                         $rating_html = wc_get_rating_html( $shop_isle_avg );
199                                 }
200                         } elseif ( function_exists( 'method_exists' ) && method_exists( $product, 'get_rating_html' ) && method_exists( $product, 'get_average_rating' ) ) {
201                                 $shop_isle_avg = $product->get_average_rating();
202                                 if ( ! empty( $shop_isle_avg ) ) {
203                                         $rating_html = $product->get_rating_html( $shop_isle_avg );
204                                 }
205                         }
206                         if ( ! empty( $rating_html ) && get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {
207                                 echo '<div class="product-rating-home">' . $rating_html . '</div>';
208                         }
209                         if ( function_exists( 'method_exists' ) && method_exists( $product, 'is_on_sale' ) ) {
210                                 if ( $product->is_on_sale() ) {
211                                         if ( function_exists( 'woocommerce_show_product_sale_flash' ) ) {
212                                                 woocommerce_show_product_sale_flash();
213                                         }
214                                 }
215                         }
216                         if ( function_exists( 'method_exists' ) && method_exists( $product, 'managing_stock' ) && method_exists( $product, 'is_in_stock' ) ) {
217                                 if ( ! $product->managing_stock() && ! $product->is_in_stock() ) {
218                                         echo '<span class="onsale stock out-of-stock">' . esc_html__( 'Out of Stock', 'shop-isle' ) . '</span>';
219                                 }
220                         }
221                         $shop_isle_price = '';
222                         if ( function_exists( 'method_exists' ) && method_exists( $product, 'get_price_html' ) ) {
223                                 $shop_isle_price = $product->get_price_html();
224                         }
225                         if ( ! empty( $shop_isle_price ) ) {
226                                 echo wp_kses_post( $shop_isle_price );
227                         }
228                         echo '</div>';
229                         echo '</div>';
230                         echo '</div>';
231
232                 endwhile;
233
234                 wp_reset_postdata();
235                 echo '</div>';
236
237                 echo '</div>';
238
239         endif;
240
241 endif;
242
243 echo '</div>';
244
245 echo '</section>';
246
247
248
249