/** * Add our own output of recommended products, as the plugin * uses the standard grid by default, and we need our own. * * @since Marketify 1.0 * * @return void */ function marketify_recommended_products() { global $edd_options; if (!function_exists('edd_rp_get_suggestions')) { return; } if (is_singular('download')) { global $post; $suggestion_data = edd_rp_get_suggestions($post->ID); } else { $cart_items = edd_get_cart_contents(); if (empty($cart_items)) { return; } $post_ids = wp_list_pluck($cart_items, 'id'); $user_id = is_user_logged_in() ? get_current_user_id() : false; $suggestion_data = edd_rp_get_multi_suggestions($post_ids, $user_id); } if (!is_array($suggestion_data) || empty($suggestion_data)) { return; } $suggestions = array_keys($suggestion_data); $suggested_downloads = new WP_Query(array('post__in' => $suggestions, 'post_type' => 'download', 'posts_per_page' => edd_get_option('edd_rp_suggestion_count'))); ?> <h1 class="section-title recommended-products"><span><?php _e('Recommended Products', 'marketify'); ?> </span></h1> <div class="row edd-recommended-products"> <?php while ($suggested_downloads->have_posts()) { $suggested_downloads->the_post(); ?> <div class="col-lg-3 col-md-4 col-sm-6"> <?php get_template_part('content-grid', 'download'); ?> </div> <?php } ?> </div> <?php }
/** * edd_rp_get_multi_suggestions * * Generates the suggestions for an array of post IDs * * * @since 1.0 * @param $post_ids array post IDs to get suggestions for * @param $user_id int a user ID to filter already purchased items from the return * @param $count int The number of items to display * @return array */ function edd_rp_get_multi_suggestions($post_ids = false, $user_id = false, $count = false) { if (!is_array($post_ids) || count($post_ids) == 0) { return false; } $suggestions = array(); foreach ($post_ids as $post) { $new_suggestions = edd_rp_get_suggestions($post, $user_id, $count); if (is_array($new_suggestions)) { $suggestions = $suggestions + $new_suggestions; } } if (count($suggestions) == 0) { $suggestions = array(); } else { // Remove any items from the suggestions that were used as the basis foreach ($post_ids as $post_id) { if (isset($suggestions[$post_id])) { unset($suggestions[$post_id]); } } // Sort by the most times purchased arsort($suggestions); } // If we didn't get a new length to slice to ( usually from short codes ) if (empty($count)) { $count = apply_filters('edd_rp_multi_recommendation_count', edd_get_option('edd_rp_suggestion_count', 3)); } return apply_filters('edd_rp_multi_recommendation_results', array_slice($suggestions, 0, $count, true)); }
<?php global $post; $suggestion_data = edd_rp_get_suggestions($post->ID); if (is_array($suggestion_data) && !empty($suggestion_data)) { $suggestions = array_keys($suggestion_data); $suggested_downloads = new WP_Query(array('post__in' => $suggestions, 'post_type' => 'download')); if ($suggested_downloads->have_posts()) { ?> <div id="edd-rp-single-wrapper"> <h5 id="edd-rp-single-header"><?php echo sprintf(__('Users who purchased %s, also purchased:', 'edd-rp-txt'), get_the_title()); ?> </h5> <div id="edd-rp-items-wrapper" class="edd-rp-single"> <?php while ($suggested_downloads->have_posts()) { ?> <?php $suggested_downloads->the_post(); ?> <div class="edd-rp-item <?php echo !current_theme_supports('post-thumbnails') ? 'edd-rp-nothumb' : ''; ?> "> <a href="<?php the_permalink(); ?> "> <?php the_title();