add-to-cart
11 months ago
additional-information
3 years ago
advanced-search
11 months ago
archive-description
3 years ago
archive-products
11 months ago
archive-result-count
2 years ago
archive-title
11 months ago
archive-view-mode
2 years ago
breadcrumbs
4 years ago
call-for-price
11 months ago
cart-table
11 months ago
cart-totals
2 years ago
checkout-coupon-form
3 years ago
checkout-form-additional
3 years ago
checkout-form-billing
2 years ago
checkout-form-login
3 years ago
checkout-form-shipping
2 years ago
checkout-payment
3 years ago
checkout-review-order
2 years ago
checkout-shipping-methods
2 years ago
cross-sells
11 months ago
deal-products
2 years ago
empty-cart-message
2 years ago
filter-orderby
2 years ago
filter-products-per-page
3 years ago
filterable-product-list
11 months ago
init
11 months ago
notice
2 years ago
product-categories
3 years ago
product-category-lists
11 months ago
product-description
2 years ago
product-excerpt
3 years ago
product-image
11 months ago
product-list
2 years ago
product-meta
2 years ago
product-price
3 years ago
product-rating
3 years ago
product-review
2 years ago
product-share
2 years ago
product-sku
3 years ago
product-stock
11 months ago
product-tabs
2 years ago
product-tags
3 years ago
product-title
2 years ago
qr-code
11 months ago
recently-viewed-products
11 months ago
related
11 months ago
return-to-shop
2 years ago
up-sells
11 months ago
view-single-product
3 years ago
lazy-cache.php
3 years ago
manifest.php
11 months ago
prod-short-code.php
2 years ago
products.php
3 years ago
shop.php
3 years ago
widget-helper.php
2 years ago
prod-short-code.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Widgets; |
| 4 | defined('ABSPATH') || exit; |
| 5 | |
| 6 | class Prod_Short_Code extends \WC_Shortcode_Products { |
| 7 | |
| 8 | public function __construct($settings = array(), $type = 'products') { |
| 9 | |
| 10 | $this->settings = $settings; |
| 11 | $this->type = $type; |
| 12 | |
| 13 | $this->attributes = $this->parse_attributes([ |
| 14 | 'columns' => $settings['shopengine_columns'], |
| 15 | 'rows' => $settings['shopengine_rows'], |
| 16 | 'paginate' => $settings['shopengine_paginate'], |
| 17 | 'cache' => false, |
| 18 | ]); |
| 19 | |
| 20 | $this->query_args = $this->parse_query_args(); |
| 21 | } |
| 22 | |
| 23 | |
| 24 | protected function parse_query_args() { |
| 25 | |
| 26 | $query_args = [ |
| 27 | 'post_type' => 'product', |
| 28 | 'post_status' => 'publish', |
| 29 | 'ignore_sticky_posts' => true, |
| 30 | 'no_found_rows' => false === wc_string_to_bool($this->attributes['paginate']), |
| 31 | ]; |
| 32 | |
| 33 | $settings = $this->settings; |
| 34 | |
| 35 | if($settings['shopengine_paginate'] === 'yes') { |
| 36 | //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- It's a fronted user part, not possible to verify nonce here |
| 37 | $page = empty( $_GET['product-page'] ) ? 1 : absint($_GET['product-page']); |
| 38 | |
| 39 | if ($page > 1) { |
| 40 | $query_args['paged'] = $page; |
| 41 | } |
| 42 | |
| 43 | $ord_arg = WC()->query->get_catalog_ordering_args(); |
| 44 | |
| 45 | $query_args['orderby'] = $ord_arg['orderby']; |
| 46 | $query_args['order'] = $ord_arg['order']; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | $query_args['fields'] = 'ids'; |
| 51 | $query_args['post_type'] = 'product'; |
| 52 | $query_args['posts_per_page'] = intval($settings['shopengine_columns'] * $settings['shopengine_rows']); |
| 53 | |
| 54 | |
| 55 | return $query_args; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | protected function get_query_results() { |
| 60 | |
| 61 | $results = parent::get_query_results(); |
| 62 | |
| 63 | return $results; |
| 64 | } |
| 65 | } |