about-widget.php
1 year ago
accordion-widget.php
1 year ago
accordion.php
1 year ago
attachment-url.php
1 year ago
audio.php
1 year ago
before-after.php
1 year ago
button.php
1 year ago
code.php
1 year ago
contact-box.php
1 year ago
contact-form.php
1 year ago
custom-list.php
6 months ago
divider.php
1 year ago
dropcap.php
1 year ago
facebook.php
1 year ago
flickr.php
1 year ago
gallery.php
1 year ago
gmap.php
1 year ago
highlight.php
1 year ago
image.php
1 year ago
instagram-feed.php
1 year ago
latest-posts-slider.php
1 year ago
popular-posts-widget.php
1 year ago
products-grid.php
1 year ago
quote.php
1 year ago
recent-posts-grid-carousel.php
1 year ago
recent-posts-land-style.php
1 year ago
recent-posts-masonry.php
1 year ago
recent-posts-tiles-carousel.php
1 year ago
recent-posts-tiles.php
1 year ago
recent-posts-timeline.php
1 year ago
recent-posts-widget.php
1 year ago
recent-products.php
1 year ago
related-posts.php
8 years ago
sample-element.php
1 year ago
search.php
1 year ago
socials-list.php
1 year ago
staff.php
1 year ago
tab-widget.php
1 year ago
tabs.php
1 year ago
testimonial.php
1 year ago
text.php
1 year ago
touch-slider.php
1 year ago
video.php
1 year ago
recent-products.php
644 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Woocommerce Recent Products Element |
| 4 | * |
| 5 | * |
| 6 | * @package Auxin |
| 7 | * @license LICENSE.txt |
| 8 | * @author averta |
| 9 | * @link http://phlox.pro/ |
| 10 | * @copyright (c) 2010-2025 averta |
| 11 | */ |
| 12 | function auxin_get_the_recent_products_master_array( $master_array ) { |
| 13 | |
| 14 | $master_array['aux_recent_product'] = array( |
| 15 | 'name' => __("Recent Products", 'auxin-elements' ), |
| 16 | 'auxin_output_callback' => 'auxin_widget_the_recent_products_callback', |
| 17 | 'base' => 'aux_recent_product', |
| 18 | 'description' => __("a Widget for Display Your Store's Products", 'auxin-elements' ), |
| 19 | 'class' => 'aux-widget-recent-products', |
| 20 | 'show_settings_on_create' => true, |
| 21 | 'weight' => 1, |
| 22 | 'category' => THEME_NAME, |
| 23 | 'is_widget' => true, |
| 24 | 'is_shortcode' => true, |
| 25 | 'group' => '', |
| 26 | 'admin_enqueue_js' => '', |
| 27 | 'admin_enqueue_css' => '', |
| 28 | 'front_enqueue_js' => '', |
| 29 | 'front_enqueue_css' => '', |
| 30 | 'icon' => 'aux-element aux-pb-icons-grid', |
| 31 | 'custom_markup' => '', |
| 32 | 'js_view' => '', |
| 33 | 'html_template' => '', |
| 34 | 'deprecated' => '', |
| 35 | 'content_element' => '', |
| 36 | 'as_parent' => '', |
| 37 | 'as_child' => '', |
| 38 | 'params' => array( |
| 39 | array( |
| 40 | 'heading' => __('Title','auxin-elements' ), |
| 41 | 'description' => __('Recent products title, leave it empty if you don`t need title.', 'auxin-elements'), |
| 42 | 'param_name' => 'title', |
| 43 | 'type' => 'textfield', |
| 44 | 'value' => '', |
| 45 | 'holder' => 'textfield', |
| 46 | 'class' => 'title', |
| 47 | 'admin_label' => false, |
| 48 | 'dependency' => '', |
| 49 | 'weight' => '', |
| 50 | 'group' => '', |
| 51 | 'edit_field_class' => '' |
| 52 | ), |
| 53 | array( |
| 54 | 'heading' => __('Subtitle','auxin-elements' ), |
| 55 | 'description' => __('Recent products subtitle, leave it empty if you don`t need title.', 'auxin-elements'), |
| 56 | 'param_name' => 'subtitle', |
| 57 | 'type' => 'textfield', |
| 58 | 'value' => '', |
| 59 | 'holder' => 'textfield', |
| 60 | 'class' => 'title', |
| 61 | 'admin_label' => false, |
| 62 | 'dependency' => '', |
| 63 | 'weight' => '', |
| 64 | 'group' => '', |
| 65 | 'edit_field_class' => '' |
| 66 | ), |
| 67 | array( |
| 68 | 'heading' => __('Categories', 'auxin-elements'), |
| 69 | 'description' => __('Specifies a category that you want to show posts from it.', 'auxin-elements' ), |
| 70 | 'param_name' => 'cat', |
| 71 | 'type' => 'aux_taxonomy', |
| 72 | 'taxonomy' => 'product_cat', |
| 73 | 'def_value' => ' ', |
| 74 | 'holder' => '', |
| 75 | 'class' => 'cat', |
| 76 | 'value' => ' ', // should use the taxonomy name |
| 77 | 'admin_label' => false, |
| 78 | 'dependency' => '', |
| 79 | 'weight' => '', |
| 80 | 'group' => 'Query', |
| 81 | 'edit_field_class' => '' |
| 82 | ), |
| 83 | array( |
| 84 | 'heading' => __('Image aspect ratio', 'auxin-elements'), |
| 85 | 'description' => '', |
| 86 | 'param_name' => 'image_aspect_ratio', |
| 87 | 'type' => 'dropdown', |
| 88 | 'def_value' => '0.75', |
| 89 | 'holder' => '', |
| 90 | 'class' => 'order', |
| 91 | 'value' =>array ( |
| 92 | '0.75' => __('Horizontal 4:3' , 'auxin-elements'), |
| 93 | '0.56' => __('Horizontal 16:9', 'auxin-elements'), |
| 94 | '1.00' => __('Square 1:1' , 'auxin-elements'), |
| 95 | '1.33' => __('Vertical 3:4' , 'auxin-elements'), |
| 96 | '1.5' => __('Vertical 10:15' , 'auxin-elements'), |
| 97 | |
| 98 | ), |
| 99 | 'admin_label' => false, |
| 100 | 'dependency' => '', |
| 101 | 'weight' => '', |
| 102 | 'group' => '', |
| 103 | 'edit_field_class' => '' |
| 104 | ), |
| 105 | array( |
| 106 | 'heading' => __('Exclude posts without media','auxin-elements' ), |
| 107 | 'description' => '', |
| 108 | 'param_name' => 'exclude_without_media', |
| 109 | 'type' => 'aux_switch', |
| 110 | 'value' => '0', |
| 111 | 'class' => '', |
| 112 | 'admin_label' => false, |
| 113 | 'dependency' => '', |
| 114 | 'weight' => '', |
| 115 | 'group' => 'Query', |
| 116 | 'edit_field_class' => '' |
| 117 | ), |
| 118 | array( |
| 119 | 'heading' => __('Order by', 'auxin-elements'), |
| 120 | 'description' => '', |
| 121 | 'param_name' => 'order_by', |
| 122 | 'type' => 'dropdown', |
| 123 | 'def_value' => 'date', |
| 124 | 'holder' => '', |
| 125 | 'class' => 'order_by', |
| 126 | 'value' => array ( |
| 127 | 'date' => __('Date', 'auxin-elements'), |
| 128 | 'menu_order date' => __('Menu Order', 'auxin-elements'), |
| 129 | 'title' => __('Title', 'auxin-elements'), |
| 130 | 'ID' => __('ID', 'auxin-elements'), |
| 131 | 'rand' => __('Random', 'auxin-elements'), |
| 132 | 'comment_count' => __('Comments', 'auxin-elements'), |
| 133 | 'modified' => __('Date Modified', 'auxin-elements'), |
| 134 | 'author' => __('Author', 'auxin-elements'), |
| 135 | 'post__in' => __('Inserted Post IDs', 'auxin-elements') |
| 136 | ), |
| 137 | 'admin_label' => false, |
| 138 | 'dependency' => '', |
| 139 | 'weight' => '', |
| 140 | 'group' => 'Query', |
| 141 | 'edit_field_class' => '' |
| 142 | ), |
| 143 | array( |
| 144 | 'heading' => __('Order', 'auxin-elements'), |
| 145 | 'description' => '', |
| 146 | 'param_name' => 'order', |
| 147 | 'type' => 'dropdown', |
| 148 | 'def_value' => 'DESC', |
| 149 | 'holder' => '', |
| 150 | 'class' => 'order', |
| 151 | 'value' =>array ( |
| 152 | 'DESC' => __('Descending', 'auxin-elements'), |
| 153 | 'ASC' => __('Ascending', 'auxin-elements'), |
| 154 | ), |
| 155 | 'admin_label' => false, |
| 156 | 'dependency' => '', |
| 157 | 'weight' => '', |
| 158 | 'group' => 'Query', |
| 159 | 'edit_field_class' => '' |
| 160 | ), |
| 161 | array( |
| 162 | 'heading' => __('Only products','auxin-elements' ), |
| 163 | 'description' => __('If you intend to display ONLY specific products, you should specify the products here. You have to insert the Products IDs that are separated by comma (eg. 53,34,87,25).', 'auxin-elements' ), |
| 164 | 'param_name' => 'only_products__in', |
| 165 | 'type' => 'textfield', |
| 166 | 'value' => '', |
| 167 | 'holder' => '', |
| 168 | 'class' => '', |
| 169 | 'admin_label' => false, |
| 170 | 'dependency' => '', |
| 171 | 'weight' => '', |
| 172 | 'group' => 'Query', |
| 173 | 'edit_field_class' => '' |
| 174 | ), |
| 175 | array( |
| 176 | 'heading' => __('Include products','auxin-elements' ), |
| 177 | 'description' => __('If you intend to include additional products, you should specify the products here. You have to insert the Products IDs that are separated by comma (eg. 53,34,87,25)', 'auxin-elements' ), |
| 178 | 'param_name' => 'include', |
| 179 | 'type' => 'textfield', |
| 180 | 'value' => '', |
| 181 | 'holder' => '', |
| 182 | 'class' => '', |
| 183 | 'admin_label' => false, |
| 184 | 'dependency' => '', |
| 185 | 'weight' => '', |
| 186 | 'group' => 'Query', |
| 187 | 'edit_field_class' => '' |
| 188 | ), |
| 189 | array( |
| 190 | 'heading' => __('Exclude products','auxin-elements' ), |
| 191 | 'description' => __('If you intend to exclude specific products from result, you should specify the products here. You have to insert the Products IDs that are separated by comma (eg. 53,34,87,25)', 'auxin-elements' ), |
| 192 | 'param_name' => 'exclude', |
| 193 | 'type' => 'textfield', |
| 194 | 'value' => '', |
| 195 | 'holder' => '', |
| 196 | 'class' => '', |
| 197 | 'admin_label' => false, |
| 198 | 'dependency' => '', |
| 199 | 'weight' => '', |
| 200 | 'group' => 'Query', |
| 201 | 'edit_field_class' => '' |
| 202 | ), |
| 203 | array( |
| 204 | 'heading' => __('Start offset','auxin-elements' ), |
| 205 | 'description' => __('Number of products to displace or pass over.', 'auxin-elements' ), |
| 206 | 'param_name' => 'offset', |
| 207 | 'type' => 'textfield', |
| 208 | 'value' => '', |
| 209 | 'holder' => '', |
| 210 | 'class' => '', |
| 211 | 'admin_label' => false, |
| 212 | 'dependency' => '', |
| 213 | 'weight' => '', |
| 214 | 'group' => 'Query', |
| 215 | 'edit_field_class' => '' |
| 216 | ), |
| 217 | array( |
| 218 | 'heading' => __('Display products price', 'auxin-elements' ), |
| 219 | 'param_name' => 'display_price', |
| 220 | 'type' => 'aux_switch', |
| 221 | 'def_value' => '', |
| 222 | 'value' => '1', |
| 223 | 'holder' => '', |
| 224 | 'class' => 'display_price', |
| 225 | 'admin_label' => false, |
| 226 | 'dependency' => '', |
| 227 | 'weight' => '', |
| 228 | 'group' => '', |
| 229 | 'edit_field_class' => '' |
| 230 | ), |
| 231 | array( |
| 232 | 'heading' => __('Display sale badge', 'auxin-elements' ), |
| 233 | 'param_name' => 'display_sale_badge', |
| 234 | 'type' => 'aux_switch', |
| 235 | 'def_value' => '', |
| 236 | 'value' => '1', |
| 237 | 'holder' => '', |
| 238 | 'class' => 'display_sale_badge', |
| 239 | 'admin_label' => false, |
| 240 | 'dependency' => '', |
| 241 | 'weight' => '', |
| 242 | 'group' => '', |
| 243 | 'edit_field_class' => '' |
| 244 | ), |
| 245 | array( |
| 246 | 'heading' => __('Display product title','auxin-elements' ), |
| 247 | 'description' => '', |
| 248 | 'param_name' => 'display_title', |
| 249 | 'type' => 'aux_switch', |
| 250 | 'value' => '1', |
| 251 | 'class' => 'display_title', |
| 252 | 'admin_label' => false, |
| 253 | 'dependency' => '', |
| 254 | 'weight' => '', |
| 255 | 'group' => '', |
| 256 | 'edit_field_class' => '' |
| 257 | ), |
| 258 | array( |
| 259 | 'heading' => __('Display Categories','auxin-elements' ), |
| 260 | 'description' => '', |
| 261 | 'param_name' => 'display_categories', |
| 262 | 'type' => 'aux_switch', |
| 263 | 'value' => '1', |
| 264 | 'holder' => '', |
| 265 | 'class' => 'display_categories', |
| 266 | 'admin_label' => false, |
| 267 | 'weight' => '', |
| 268 | 'group' => '', |
| 269 | 'edit_field_class' => '' |
| 270 | ), |
| 271 | array( |
| 272 | 'heading' => __('Number of columns', 'auxin-elements'), |
| 273 | 'description' => '', |
| 274 | 'param_name' => 'desktop_cnum', |
| 275 | 'type' => 'dropdown', |
| 276 | 'def_value' => '4', |
| 277 | 'holder' => '', |
| 278 | 'class' => 'num', |
| 279 | 'value' => array( |
| 280 | '1' => '1', '2' => '2', '3' => '3', |
| 281 | '4' => '4', '5' => '5', '6' => '6' |
| 282 | ), |
| 283 | 'admin_label' => false, |
| 284 | 'dependency' => '', |
| 285 | 'weight' => '', |
| 286 | 'group' => 'Layout', |
| 287 | 'edit_field_class' => '' |
| 288 | ), |
| 289 | array( |
| 290 | 'heading' => __('Number of columns in tablet size', 'auxin-elements'), |
| 291 | 'description' => '', |
| 292 | 'param_name' => 'tablet_cnum', |
| 293 | 'type' => 'dropdown', |
| 294 | 'def_value' => 'inherit', |
| 295 | 'holder' => '', |
| 296 | 'class' => 'num', |
| 297 | 'value' => array( |
| 298 | 'inherit' => 'Inherited from larger', |
| 299 | '1' => '1', '2' => '2', '3' => '3', |
| 300 | '4' => '4', '5' => '5', '6' => '6' |
| 301 | ), |
| 302 | 'admin_label' => false, |
| 303 | 'dependency' => '', |
| 304 | 'weight' => '', |
| 305 | 'group' => 'Layout', |
| 306 | 'edit_field_class' => '' |
| 307 | ), |
| 308 | array( |
| 309 | 'heading' => __('Number of columns in phone size', 'auxin-elements'), |
| 310 | 'description' => '', |
| 311 | 'param_name' => 'phone_cnum', |
| 312 | 'type' => 'dropdown', |
| 313 | 'def_value' => '1', |
| 314 | 'holder' => '', |
| 315 | 'class' => 'num', |
| 316 | 'value' => array( |
| 317 | '1' => '1', '2' => '2', '3' => '3' |
| 318 | ), |
| 319 | 'admin_label' => false, |
| 320 | 'dependency' => '', |
| 321 | 'weight' => '', |
| 322 | 'group' => 'Layout', |
| 323 | 'edit_field_class' => '' |
| 324 | ), |
| 325 | // array( |
| 326 | // 'heading' => __('Content layout', 'auxin-elements'), |
| 327 | // 'description' => __('Specifies the style of content for each post column.', 'auxin-elements' ), |
| 328 | // 'param_name' => 'content_layout', |
| 329 | // 'type' => 'dropdown', |
| 330 | // 'def_value' => 'default', |
| 331 | // 'holder' => '', |
| 332 | // 'class' => 'content_layout', |
| 333 | // 'value' =>array ( |
| 334 | // 'default' => __('Full Content', 'auxin-elements'), |
| 335 | // 'entry-boxed' => __('Boxed Content', 'auxin-elements') |
| 336 | // ), |
| 337 | // 'admin_label' => false, |
| 338 | // 'dependency' => '', |
| 339 | // 'weight' => '', |
| 340 | // 'group' => '', |
| 341 | // 'edit_field_class' => '' |
| 342 | // ), |
| 343 | array( |
| 344 | 'heading' => __('Extra class name','auxin-elements' ), |
| 345 | 'description' => __('If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.', 'auxin-elements' ), |
| 346 | 'param_name' => 'extra_classes', |
| 347 | 'type' => 'textfield', |
| 348 | 'value' => '', |
| 349 | 'def_value' => '', |
| 350 | 'holder' => '', |
| 351 | 'class' => 'extra_classes', |
| 352 | 'admin_label' => false, |
| 353 | 'dependency' => '', |
| 354 | 'weight' => '', |
| 355 | 'group' => '', |
| 356 | 'edit_field_class' => '' |
| 357 | ) |
| 358 | ) |
| 359 | ); |
| 360 | |
| 361 | return $master_array; |
| 362 | } |
| 363 | |
| 364 | add_filter( 'auxin_master_array_shortcodes', 'auxin_get_the_recent_products_master_array', 10, 1 ); |
| 365 | |
| 366 | function auxin_widget_the_recent_products_callback( $atts, $shortcode_content = null ){ |
| 367 | |
| 368 | // Defining default attributes |
| 369 | $default_atts = array( |
| 370 | 'title' => '', // header title (required) |
| 371 | 'subtitle' => '', // header subtitle |
| 372 | 'cat' => ' ', |
| 373 | 'num' => '8', // max generated entry |
| 374 | 'only_products__in' => '', // display only these post IDs. array or string comma separated |
| 375 | 'include' => '', // include these post IDs in result too. array or string comma separated |
| 376 | 'exclude' => '', // exclude these post IDs from result. array or string comma separated |
| 377 | 'offset' => '', |
| 378 | 'paged' => 1, |
| 379 | 'post_type' => 'product', |
| 380 | 'taxonomy_name' => 'product_cat', // the taxonomy that we intent to display in post info |
| 381 | 'tax_args' => '', |
| 382 | 'order_by' => 'date', |
| 383 | 'order' => 'DESC', |
| 384 | 'exclude_without_media' => 0, |
| 385 | 'display_title' => true, |
| 386 | 'show_media' => true, |
| 387 | 'display_categories' => true, |
| 388 | 'display_button' => true, |
| 389 | 'preloadable' => false, |
| 390 | 'preload_preview' => true, |
| 391 | 'preload_bgcolor' => '', |
| 392 | // 'content_layout' => '', // entry-boxed |
| 393 | 'image_aspect_ratio' => 0.75, |
| 394 | 'desktop_cnum' => 4, |
| 395 | 'tablet_cnum' => 'inherit', |
| 396 | 'phone_cnum' => '1', |
| 397 | 'display_price' => true, |
| 398 | 'display_sale_badge' => true, |
| 399 | 'extra_classes' => '', |
| 400 | 'template_part_file' => 'recent-products', |
| 401 | 'extra_template_path' => AUXELS_PUB_DIR . '/templates/woocommerce', |
| 402 | 'universal_id' => '', |
| 403 | 'use_wp_query' => false, // true to use the global wp_query, false to use internal custom query |
| 404 | 'reset_query' => true, |
| 405 | 'wp_query_args' => array(), // additional wp_query args |
| 406 | 'custom_wp_query' => '', |
| 407 | 'base' => 'aux_recent_products', |
| 408 | 'base_class' => 'aux-widget-recent-products', |
| 409 | 'show_pagination' => '' |
| 410 | ); |
| 411 | |
| 412 | $result = auxin_get_widget_scafold( $atts, $default_atts, $shortcode_content ); |
| 413 | extract( $result['parsed_atts'] ); |
| 414 | |
| 415 | $acceptedTemplateFiles = apply_filters( 'auxin_recent_products_accepted_template_files', [ |
| 416 | 'recent-products', |
| 417 | ]); |
| 418 | |
| 419 | if ( ! in_array( $template_part_file, $acceptedTemplateFiles ) ) { |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | // get content width |
| 424 | global $aux_content_width; |
| 425 | |
| 426 | ob_start(); |
| 427 | |
| 428 | if( empty( $cat ) || $cat == " " || ( is_array( $cat ) && in_array( " ", $cat ) ) ) { |
| 429 | $tax_args = array(); |
| 430 | } else { |
| 431 | $tax_args = array( |
| 432 | array( |
| 433 | 'taxonomy' => $taxonomy_name, |
| 434 | 'field' => 'term_id', |
| 435 | 'terms' => ! is_array( $cat ) ? explode( ",", $cat ) : $cat |
| 436 | ) |
| 437 | ); |
| 438 | } |
| 439 | |
| 440 | if( $custom_wp_query ){ |
| 441 | $wp_query = $custom_wp_query; |
| 442 | |
| 443 | } elseif( ! $use_wp_query ){ |
| 444 | |
| 445 | // create wp_query to get latest items --------------------------------- |
| 446 | $args = array( |
| 447 | 'post_type' => $post_type, |
| 448 | 'orderby' => $order_by, |
| 449 | 'order' => $order, |
| 450 | 'offset' => $offset, |
| 451 | 'paged' => $paged, |
| 452 | 'tax_query' => $tax_args, |
| 453 | 'post_status' => 'publish', |
| 454 | 'posts_per_page' => $num, |
| 455 | 'ignore_sticky_posts' => 1, |
| 456 | |
| 457 | 'include_posts__in' => $include, // include posts in this list |
| 458 | 'posts__not_in' => $exclude, // exclude posts in this list |
| 459 | 'posts__in' => $only_products__in, // only posts in this list |
| 460 | |
| 461 | 'exclude_without_media' => $exclude_without_media, |
| 462 | ); |
| 463 | |
| 464 | // --------------------------------------------------------------------- |
| 465 | |
| 466 | // add the additional query args if available |
| 467 | if( $wp_query_args ){ |
| 468 | $args = wp_parse_args( $wp_query_args, $args ); |
| 469 | } |
| 470 | |
| 471 | // pass the args through the auxin query parser |
| 472 | $wp_query = new WP_Query( auxin_parse_query_args( $args ) ); |
| 473 | } else { |
| 474 | |
| 475 | global $wp_query; |
| 476 | } |
| 477 | |
| 478 | // widget header ------------------------------ |
| 479 | echo wp_kses_post( $result['widget_header'] ); |
| 480 | echo wp_kses_post( $result['widget_title'] ); |
| 481 | echo '<h4 class="aux-h4 widget-subtitle">' . esc_html( $subtitle ) . '</h4>'; |
| 482 | |
| 483 | $phone_break_point = 767; |
| 484 | $tablet_break_point = 1025; |
| 485 | |
| 486 | $show_comments = true; // shows comments icon |
| 487 | $post_counter = 0; |
| 488 | $column_class = ''; |
| 489 | $item_class = ''; |
| 490 | |
| 491 | $columns_custom_styles = ''; |
| 492 | |
| 493 | if( ! empty( $loadmore_type ) ) { |
| 494 | $item_class .= ' aux-ajax-item'; |
| 495 | } |
| 496 | |
| 497 | $column_class .= ''; |
| 498 | $item_class .= ' aux-recent-product-item aux-col'; |
| 499 | |
| 500 | // Specifies whether the columns have footer meta or not |
| 501 | $column_class .= ' aux-recent-products-wrapper aux-row aux-ajax-view aux-de-col' . $desktop_cnum; |
| 502 | |
| 503 | $tablet_cnum = ('inherit' == $tablet_cnum ) ? $desktop_cnum : $tablet_cnum ; |
| 504 | $column_class .= ' aux-tb-col'.$tablet_cnum . ' aux-mb-col'.$phone_cnum; |
| 505 | |
| 506 | |
| 507 | // automatically calculate the media size if was empty |
| 508 | if( empty( $size ) ){ |
| 509 | $column_media_width = auxin_get_content_column_width( $desktop_cnum, 15, $content_width ); |
| 510 | $size = array( 'width' => $column_media_width, 'height' => $column_media_width * $image_aspect_ratio ); |
| 511 | } |
| 512 | |
| 513 | if ( !empty( $show_pagination ) ) { |
| 514 | $requiredData = array( |
| 515 | 'display_price' => $result['parsed_atts']['display_price'], |
| 516 | 'display_sale_badge' => $result['parsed_atts']['display_sale_badge'], |
| 517 | 'show_media' => $result['parsed_atts']['show_media'], |
| 518 | 'preloadable' => $result['parsed_atts']['preloadable'], |
| 519 | 'preload_preview' => $result['parsed_atts']['preload_preview'], |
| 520 | 'preload_bgcolor' => $result['parsed_atts']['preload_bgcolor'], |
| 521 | 'display_title' => $result['parsed_atts']['display_title'], |
| 522 | 'display_categories' => $result['parsed_atts']['display_categories'], |
| 523 | 'display_button' => $result['parsed_atts']['display_button'], |
| 524 | 'desktop_cnum' => $result['parsed_atts']['desktop_cnum'], |
| 525 | 'tablet_cnum' => $result['parsed_atts']['tablet_cnum'], |
| 526 | 'phone_cnum' => $result['parsed_atts']['phone_cnum'], |
| 527 | 'cat' => $result['parsed_atts']['cat'], |
| 528 | 'num' => $result['parsed_atts']['num'], |
| 529 | 'exclude_without_media' => $result['parsed_atts']['exclude_without_media'], |
| 530 | 'order_by' => $result['parsed_atts']['order_by'], |
| 531 | 'order' => $result['parsed_atts']['order'], |
| 532 | 'only_products__in' => $result['parsed_atts']['only_products__in'], |
| 533 | 'include' => $result['parsed_atts']['include'], |
| 534 | 'exclude' => $result['parsed_atts']['exclude'], |
| 535 | 'offset' => $result['parsed_atts']['offset'], |
| 536 | 'show_pagination' => $result['parsed_atts']['show_pagination'], |
| 537 | 'image_aspect_ratio' => $result['parsed_atts']['image_aspect_ratio'], |
| 538 | ); |
| 539 | |
| 540 | echo '<div class="aux-isotope-animated"><div class="aux-items-loading aux-loading-hide"><div class="aux-loading-loop"><svg class="aux-circle" width="100%" height="100%" viewBox="0 0 42 42"><circle class="aux-stroke-bg" r="20" cx="21" cy="21" fill="none"></circle><circle class="aux-progress" r="20" cx="21" cy="21" fill="none" transform="rotate(-90 21 21)"></circle></svg></div></div></div>'; |
| 541 | } |
| 542 | |
| 543 | echo '<div class="'. esc_attr( $column_class ) .'" ' . ( !empty( $show_pagination ) ? "data-widget-data='" . auxin_escape_json( $requiredData ) . "'" : '' ) . ">"; |
| 544 | |
| 545 | $have_posts = $wp_query->have_posts(); |
| 546 | |
| 547 | if( $have_posts ){ |
| 548 | |
| 549 | while ( $wp_query->have_posts() ) { |
| 550 | |
| 551 | $wp_query->the_post(); |
| 552 | $post = get_post(); |
| 553 | |
| 554 | $post_vars = auxin_get_post_type_media_args( |
| 555 | $post, |
| 556 | array( |
| 557 | 'post_type' => $post_type, |
| 558 | 'request_from' => 'element', |
| 559 | 'media_width' => $phone_break_point, |
| 560 | 'media_size' => $size, |
| 561 | 'upscale_image' => true, |
| 562 | 'image_from_content' => ! $exclude_without_media, // whether to try to get image from content or not |
| 563 | 'ignore_media' => ! $show_media, |
| 564 | 'add_image_hw' => false, // whether add width and height attr or not |
| 565 | 'preloadable' => $preloadable, |
| 566 | 'preload_preview' => $preload_preview, |
| 567 | 'preload_bgcolor' => $preload_bgcolor, |
| 568 | 'image_sizes' => 'auto', |
| 569 | 'srcset_sizes' => 'auto' |
| 570 | ) |
| 571 | ); |
| 572 | |
| 573 | extract( $post_vars ); |
| 574 | $the_format = get_post_format( $post ); |
| 575 | |
| 576 | // add specific class to current classes for each column |
| 577 | $post_classes = $has_attach && $show_media ? 'post column-entry' : 'post column-entry no-media'; |
| 578 | |
| 579 | // Generate the markup by template parts |
| 580 | if( has_action( $base_class . '-template-part' ) ){ |
| 581 | do_action( $base_class . '-template-part', $result, $post_vars, $item_class ); |
| 582 | |
| 583 | } else { |
| 584 | ?> |
| 585 | <div <?php wc_product_class( $item_class . ' post-'. $post->ID, $post->ID );?>> |
| 586 | <?php |
| 587 | include auxin_get_template_file( $template_part_file, '', $extra_template_path ); |
| 588 | echo '</div>'; |
| 589 | } |
| 590 | |
| 591 | } |
| 592 | |
| 593 | if( ! $skip_wrappers ) { |
| 594 | // End tag for aux-ajax-view wrapper |
| 595 | echo '</div>'; |
| 596 | } else { |
| 597 | // Get post counter in the query |
| 598 | echo '<span class="aux-post-count hidden">'. esc_html( $wp_query->post_count ) .'</span>'; |
| 599 | echo '<span class="aux-all-posts-count hidden">'. esc_html( $wp_query->found_posts ) .'</span>'; |
| 600 | } |
| 601 | |
| 602 | if ( !empty( $show_pagination ) ) { |
| 603 | echo auxin_the_paginate_nav( [ |
| 604 | 'wp_query' => $wp_query, |
| 605 | 'current' => $args['paged'] |
| 606 | ] ); |
| 607 | } |
| 608 | |
| 609 | } |
| 610 | |
| 611 | if( $reset_query ){ |
| 612 | wp_reset_postdata(); |
| 613 | } |
| 614 | |
| 615 | // return false if no result found |
| 616 | if( ! $have_posts ){ |
| 617 | ob_get_clean(); |
| 618 | return false; |
| 619 | } |
| 620 | |
| 621 | // widget custom output ----------------------- |
| 622 | |
| 623 | |
| 624 | // widget footer ------------------------------ |
| 625 | echo wp_kses_post( $result['widget_footer'] ); |
| 626 | |
| 627 | return ob_get_clean(); |
| 628 | } |
| 629 | |
| 630 | function auxin_ajax_widget_the_recent_products(){ |
| 631 | |
| 632 | if ( !isset( $_GET['auxinNonce'] ) || !wp_verify_nonce( $_GET['auxinNonce'], 'auxin-security-nonce' ) ) { |
| 633 | die(); |
| 634 | } |
| 635 | |
| 636 | $args = !empty($_GET['data']) ? auxin_sanitize_input( $_GET['data'] ) : []; |
| 637 | |
| 638 | $args['paged'] = !empty($_GET['paged']) ? sanitize_text_field( $_GET['paged'] ) : $args['paged']; |
| 639 | |
| 640 | echo auxin_widget_the_recent_products_callback( $args ); |
| 641 | die(); |
| 642 | } |
| 643 | add_action( 'wp_ajax_aux_the_recent_products', 'auxin_ajax_widget_the_recent_products' ); |
| 644 | add_action( 'wp_ajax_nopriv_aux_the_recent_products', 'auxin_ajax_widget_the_recent_products'); |