account-address
4 years ago
account-dashboard
4 years ago
account-details
4 years ago
account-downloads
4 years ago
account-form-login
4 years ago
account-form-register
4 years ago
account-logout
4 years ago
account-navigation
4 years ago
account-order-details
4 years ago
account-orders
4 years ago
add-to-cart
4 years ago
additional-information
4 years ago
advanced-search
4 years ago
archive-description
4 years ago
archive-products
4 years ago
archive-result-count
4 years ago
archive-title
4 years ago
archive-view-mode
4 years ago
breadcrumbs
4 years ago
cart-table
4 years ago
cart-totals
4 years ago
categories
4 years ago
checkout-coupon-form
4 years ago
checkout-form-additional
4 years ago
checkout-form-billing
4 years ago
checkout-form-login
4 years ago
checkout-form-shipping
4 years ago
checkout-payment
4 years ago
checkout-review-order
4 years ago
checkout-shipping-methods
4 years ago
cross-sells
4 years ago
deal-products
4 years ago
empty-cart-message
4 years ago
filter-orderby
4 years ago
filter-products-per-page
4 years ago
filterable-product-list
4 years ago
init
4 years ago
product-categories
4 years ago
product-category-lists
4 years ago
product-description
4 years ago
product-excerpt
4 years ago
product-filters
4 years ago
product-image
4 years ago
product-list
4 years ago
product-meta
4 years ago
product-price
4 years ago
product-rating
4 years ago
product-review
4 years ago
product-share
4 years ago
product-sku
4 years ago
product-stock
4 years ago
product-tabs
4 years ago
product-tags
4 years ago
product-title
4 years ago
recently-viewed-products
4 years ago
related
4 years ago
return-to-shop
4 years ago
thankyou-address-details
4 years ago
thankyou-order-confirm
4 years ago
thankyou-order-details
4 years ago
thankyou-thankyou
4 years ago
up-sells
4 years ago
lazy-cache.php
4 years ago
manifest.php
4 years ago
prod-short-code.php
5 years ago
products.php
4 years ago
shop.php
5 years ago
widget-helper.php
4 years ago
products.php
174 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Widgets; |
| 4 | |
| 5 | use Elementor\Controls_Manager; |
| 6 | use ShopEngine\Core\Builders\Action; |
| 7 | |
| 8 | defined('ABSPATH') || exit; |
| 9 | |
| 10 | class Products |
| 11 | { |
| 12 | use \ShopEngine\Traits\Singleton; |
| 13 | use Lazy_Cache; |
| 14 | |
| 15 | public function no_product_to_preview() { |
| 16 | return '<div class="shopengine-notice shopengine-notice-warning"> |
| 17 | '.esc_html__('There is no product to show preview. Please add some simple products first', 'shopengine').' |
| 18 | </div>'; |
| 19 | } |
| 20 | |
| 21 | public function get_a_simple_product($type = 'simple') { |
| 22 | |
| 23 | $args = [ |
| 24 | 'type' => [$type], |
| 25 | 'status' => ['publish'], |
| 26 | 'limit' => 1, |
| 27 | 'orderby' => 'ID', |
| 28 | 'order' => 'ASC' |
| 29 | ]; |
| 30 | |
| 31 | $prod = $this->cache('wc_get_products', $args); |
| 32 | |
| 33 | |
| 34 | return empty($prod[0]) ? false : $prod[0]; |
| 35 | } |
| 36 | |
| 37 | public function get_a_simple_product_id($type = 'simple') { |
| 38 | $prod = $this->get_a_simple_product($type); |
| 39 | |
| 40 | return ($prod === false) ? false : $prod->get_id(); |
| 41 | } |
| 42 | |
| 43 | public function get_a_product_id() { |
| 44 | |
| 45 | $prod = $this->get_a_simple_product(); |
| 46 | |
| 47 | return ($prod === false) ? false : $prod->get_id(); |
| 48 | } |
| 49 | |
| 50 | public function product_tab_content_preview($content) { |
| 51 | |
| 52 | $prod = $this->get_a_simple_product(); |
| 53 | |
| 54 | return ($prod === false) ? false : $prod->get_description(); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | public function get_a_orders_from_my_account() { |
| 59 | |
| 60 | $args = [ |
| 61 | 'customer' => get_current_user_id(), |
| 62 | 'limit' => 1, |
| 63 | 'return' => 'ids', |
| 64 | ]; |
| 65 | |
| 66 | $customer_orders = $this->cache('wc_get_orders-woocommerce_my_account_my_orders_query', $args); |
| 67 | |
| 68 | return empty($customer_orders) ? 0 : $customer_orders[0]; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Get order id |
| 73 | */ |
| 74 | public function get_a_order_id() { |
| 75 | return $this->cache('wc_get_orders', ['limit' => 1]); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | public function get_a_variable_product_id() { |
| 80 | |
| 81 | $args = array( |
| 82 | 'posts_per_page' => 1, |
| 83 | 'post_type' => 'product_variation', |
| 84 | 'post_status' => 'publish', |
| 85 | ); |
| 86 | |
| 87 | $product = get_posts($args); |
| 88 | $product = $this->cache('get_posts', $args); |
| 89 | |
| 90 | return empty($product[0]) ? 0 : $product[0]->post_parent; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | /** |
| 95 | * Grab a product for elementor editor preview |
| 96 | * |
| 97 | * @param $post_type |
| 98 | * @return string |
| 99 | */ |
| 100 | public function get_product($post_type) { |
| 101 | |
| 102 | global $product; |
| 103 | |
| 104 | if('product' == $post_type) { |
| 105 | return $product; |
| 106 | } |
| 107 | |
| 108 | $product = $this->get_a_simple_product(); |
| 109 | |
| 110 | return empty($product) ? new \stdClass() : $product; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | public function get_variation_product() { |
| 115 | |
| 116 | global $product; |
| 117 | |
| 118 | $post_type = get_post_type(); |
| 119 | |
| 120 | if('product' == $post_type) { |
| 121 | |
| 122 | return $product; |
| 123 | } |
| 124 | |
| 125 | $prod_id = $this->get_a_variable_product_id(); |
| 126 | |
| 127 | $product = $this->cache('wc_get_product', $prod_id); |
| 128 | |
| 129 | return empty($product) ? new \stdClass() : $product; |
| 130 | } |
| 131 | |
| 132 | |
| 133 | public function get_random_product_id() { |
| 134 | |
| 135 | global $product; |
| 136 | |
| 137 | $post_type = get_post_type(); |
| 138 | |
| 139 | if('product' == $post_type) { |
| 140 | |
| 141 | $prod_id = $product->get_id(); |
| 142 | |
| 143 | } else { |
| 144 | |
| 145 | $prod_id = $this->get_a_product_id(); |
| 146 | } |
| 147 | |
| 148 | return $prod_id; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | public function get_widget_template($widget_name, $filename = 'default') { |
| 153 | |
| 154 | $widget_name = ltrim($widget_name, 'shopengine'); |
| 155 | $widget_name = ltrim($widget_name, '-'); |
| 156 | |
| 157 | return \ShopEngine::widget_dir() . $widget_name . '/screens/' . $filename . '.php'; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | public function get_template_type_by_id($page_id) { |
| 162 | |
| 163 | $data = $this->cache('get_post_meta', [$page_id, Action::PK__SHOPENGINE_TEMPLATE, true]); |
| 164 | return empty($data['form_type']) ? '' : $data['form_type']; |
| 165 | } |
| 166 | |
| 167 | public function get_all_color_terms(){ |
| 168 | |
| 169 | $all_color_terms = $this->cache('get_all_color_terms', null); |
| 170 | |
| 171 | return $all_color_terms; |
| 172 | } |
| 173 | } |
| 174 |