/** * 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 }
function edd_rp_render_shortcode($attributes, $content = null) { global $post; extract(shortcode_atts(array('ids' => $post->id, 'user' => 'false', 'count' => 3, 'title' => __('Recommended Products', EDD_RP_TEXT_DOMAIN)), $attributes, 'recommended_products')); $ids = str_replace(' ', '', $ids); $ids = explode(',', $ids); $count = absint($count); $user_id = $user == 'true' ? get_current_user_id() : false; $suggestions = edd_rp_get_multi_suggestions($ids, $user_id, $count); if (is_array($suggestions) && !empty($suggestions)) { $suggestions = array_keys($suggestions); $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 $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(); ?> <?php if (current_theme_supports('post-thumbnails') && has_post_thumbnail(get_the_ID())) { ?> <div class="edd_cart_item_image"> <?php echo get_the_post_thumbnail(get_the_ID(), apply_filters('edd_checkout_image_size', array(125, 125))); ?> </div> <?php } else { ?> <br /> <?php } ?> </a> <?php if (!edd_has_variable_prices(get_the_ID())) { ?> <?php edd_price(get_the_ID()); ?> <?php } ?> <?php echo edd_get_purchase_link(array('download_id' => get_the_ID(), 'price' => false, 'direct' => false)); ?> </div> <?php } ?> </div> </div> <?php } ?> <?php wp_reset_postdata(); ?> <?php } }
<?php $cart_items = edd_get_cart_contents(); $post_ids = wp_list_pluck($cart_items, 'id'); ?> <?php if ($cart_items) { $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)) { $suggestions = array_keys($suggestion_data); $suggested_downloads = new WP_Query(array('post__in' => $suggestions, 'post_type' => 'download')); if ($suggested_downloads->have_posts()) { $single = __('this item', 'edd-rp-txt'); $plural = __('these items', 'edd-rp-txt'); $cart_items_text = _n($single, $plural, count($post_ids), 'edd-rp-txt'); ?> <div id="edd-rp-checkout-wrapper"> <h5 id="edd-rp-checkout-header"><?php echo sprintf(__('Users who purchased %s, also purchased:', 'edd-rp-txt'), $cart_items_text); ?> </h5> <div id="edd-rp-items-wrapper" class="edd-rp-checkout"> <?php while ($suggested_downloads->have_posts()) { ?> <?php $suggested_downloads->the_post(); ?> <div class="edd-rp-item <?php