get_results( " SELECT post.ID, post.post_parent FROM `$wpdb->posts` AS post LEFT JOIN `$wpdb->postmeta` AS meta ON post.ID = meta.post_id LEFT JOIN `$wpdb->postmeta` AS meta2 ON post.ID = meta2.post_id WHERE post.post_type IN ( 'product' ) AND post.post_status = 'publish' AND meta.meta_key = '_sale_price' AND meta2.meta_key = '_price' AND CAST( meta.meta_value AS DECIMAL ) >= 0 AND CAST( meta.meta_value AS CHAR ) != '' AND CAST( meta.meta_value AS DECIMAL ) = CAST( meta2.meta_value AS DECIMAL ) GROUP BY post.ID LIMIT 10; " ); $product_ids_on_sale = array_unique( array_map( 'absint', array_merge( wp_list_pluck( $on_sale_posts, 'ID' ), array_diff( wp_list_pluck( $on_sale_posts, 'post_parent' ), array( 0 ) ) ) ) ); set_transient( 'appmaker_wc_products_onsale', $product_ids_on_sale, 60 * 60 * 5 ); return $product_ids_on_sale; } /** * Function that returns an array containing the IDs of the featured products. * * @since 2.1 * @access public * * @param int $limit * * @return array */ static function wc_get_featured_product_ids( $limit = 10 ) { return wc_get_featured_product_ids(); } public static function get_recent_products() { $atts = array( 'per_page' => '12', 'columns' => '4', 'orderby' => 'date', 'order' => 'desc' ); extract( $atts ); $meta_query = WC()->query->get_meta_query(); $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'orderby' => $orderby, 'order' => $order, 'meta_query' => $meta_query, 'fields' => 'id=>parent', 'tax_query' => array(), ); if ( method_exists( WC()->query, 'get_tax_query' ) ) { $args['tax_query'] = WC()->query->get_tax_query( $args['tax_query'] ); } else { $args['meta_query'][] = WC()->query->visibility_meta_query(); if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { $args['meta_query'][] = array( 'key' => '_stock_status', 'value' => 'instock', 'compare' => '=', ); } } $products = get_posts( $args ); $product_ids = array_keys( $products ); $parent_ids = array_values( array_filter( $products ) ); $return_product_ids = array_unique( array_merge( $product_ids, $parent_ids ) ); return $return_product_ids; } public static function get_best_selling_products() { $atts = array( 'per_page' => '12', 'columns' => '4' ); extract( $atts ); $meta_query = WC()->query->get_meta_query(); $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'meta_key' => 'total_sales', 'orderby' => 'meta_value_num', 'meta_query' => $meta_query, 'fields' => 'id=>parent', 'tax_query' => array(), ); if ( method_exists( WC()->query, 'get_tax_query' ) ) { $args['tax_query'] = WC()->query->get_tax_query( $args['tax_query'] ); } else { $args['meta_query'][] = WC()->query->visibility_meta_query(); if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { $args['meta_query'][] = array( 'key' => '_stock_status', 'value' => 'instock', 'compare' => '=', ); } } $products = get_posts( $args ); $product_ids = array_keys( $products ); $parent_ids = array_values( array_filter( $products ) ); $return_product_ids = array_unique( array_merge( $product_ids, $parent_ids ) ); return $return_product_ids; } public static function get_top_rated_products() { $atts = array( 'per_page' => '12', 'columns' => '4', 'orderby' => 'title', 'order' => 'asc' ); extract( $atts ); $meta_query = WC()->query->get_meta_query(); $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => $orderby, 'order' => $order, 'posts_per_page' => $per_page, 'meta_query' => $meta_query, 'fields' => 'id=>parent', 'tax_query' => array(), ); $products = get_posts( $args ); $product_ids = array_keys( $products ); $parent_ids = array_values( array_filter( $products ) ); $return_product_ids = array_unique( array_merge( $product_ids, $parent_ids ) ); return $return_product_ids; } public static function get_products_by_tax($taxonomy, $tax_id) { $atts = array( 'per_page' => '12', 'columns' => '4', 'orderby' => 'title', 'order' => 'asc' ); extract( $atts ); $meta_query = WC()->query->get_meta_query(); $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => $orderby, 'order' => $order, 'posts_per_page' => $per_page, 'meta_query' => $meta_query, 'fields' => 'id=>parent', 'tax_query' => array( array( 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $tax_id, 'operator' => 'IN' ) ) ); if ( method_exists( WC()->query, 'get_tax_query' ) ) { $args['tax_query'] = WC()->query->get_tax_query( $args['tax_query'] ); } else { $args['meta_query'][] = WC()->query->visibility_meta_query(); if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { $args['meta_query'][] = array( 'key' => '_stock_status', 'value' => 'instock', 'compare' => '=', ); } } $products = get_posts( $args ); $product_ids = array_keys( $products ); $parent_ids = array_values( array_filter( $products ) ); $return_product_ids = array_unique( array_merge( $product_ids, $parent_ids ) ); return $return_product_ids; } /** * Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339. * * Requered WP 4.4 or later. * See https://developer.wordpress.org/reference/functions/mysql_to_rfc3339/ * * @since 2.6.0 * * @param string $date * * @return string|null ISO8601/RFC3339 formatted datetime. */ static function wc_rest_prepare_date_response( $date ) { // Check if mysql_to_rfc3339 exists first! if ( ! function_exists( 'mysql_to_rfc3339' ) ) { return null; } // Return null if $date is empty/zeros. if ( '0000-00-00 00:00:00' === $date || empty( $date ) ) { return null; } // Return the formatted datetime. return mysql_to_rfc3339( $date ); } static function get_id ( $object ) { if ( method_exists( $object, 'get_id' ) ){ return $object->get_id(); }else{ return $object->id; } } }