Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* List of vendors selling a particular product (SPMV), sorted by product price ASC
- *
- * Shortcode: [wcfm_vendors_card_by_product id="123"]
- *
- * @param array $attr Shortcode attributes.
- * @return string HTML output of vendor cards.
- */
- add_shortcode('wcfm_vendors_card_by_product', function ($attr) {
- global $wpdb, $WCFMmp;
- $defaults = array(
- 'id' => 0,
- );
- $atts = shortcode_atts($defaults, $attr);
- $product_id = absint(filter_input(INPUT_GET, 'id'));
- if (!$product_id && $atts['id'] && absint($atts['id'])) {
- $product_id = absint($atts['id']);
- }
- if (!$product_id) {
- return '';
- }
- $product = wc_get_product($product_id);
- if (!$product) {
- return '';
- }
- $vendor_id_single = wcfm_get_vendor_id_by_post($product_id);
- $vendor_list = [];
- $is_multi_vendor_enabled = apply_filters('wcfm_is_allow_product_multivendor_title_edit_disable', true);
- if (!$is_multi_vendor_enabled) {
- if(wcfm_is_vendor($vendor_id_single)) {
- $vendor_list[] = $vendor_id_single;
- }
- } else {
- $multi_parent_id = get_post_meta($product_id, '_is_multi_parent', true) ?: get_post_meta($product_id, '_has_multi_selling', true);
- if ($multi_parent_id) {
- $sql = $wpdb->prepare(
- "SELECT GROUP_CONCAT(product_id) as products
- FROM `{$wpdb->prefix}wcfm_marketplace_product_multivendor`
- WHERE `parent_product_id` = %d",
- $multi_parent_id
- );
- $results = $wpdb->get_row($sql);
- $product_list = isset($results->products) ? explode(',', $results->products) : array();
- if (!in_array($multi_parent_id, $product_list)) {
- array_unshift($product_list, $multi_parent_id);
- }
- $product_ids = implode(',', $product_list);
- $sql = "SELECT product_id, stock_status, stock_quantity
- FROM {$wpdb->wc_product_meta_lookup} wc_product_meta_lookup
- WHERE product_id IN (%1s)
- ORDER BY wc_product_meta_lookup.min_price ASC";
- $prepare = $wpdb->prepare($sql, $product_ids);
- $product_metas = $wpdb->get_results($prepare);
- if (!empty($product_metas)) {
- foreach ($product_metas as $product_meta) {
- if ($product_meta->stock_status === 'outofstock') {
- continue;
- }
- $post_status = get_post_status($product_meta->product_id);
- if ($post_status !== 'publish') {
- continue;
- }
- $vendor_id = wcfm_get_vendor_id_by_post($product_meta->product_id);
- if (wcfm_is_vendor($vendor_id) && !in_array($vendor_id, $vendor_list)) {
- $vendor_list[] = $vendor_id;
- }
- }
- }
- } else {
- if (wcfm_is_vendor($vendor_id_single) && !in_array($vendor_id_single, $vendor_list)) {
- $vendor_list[] = $vendor_id_single;
- }
- }
- }
- if (empty($vendor_list)) {
- return '';
- }
- ob_start();
- ?>
- <div id="wcfmmp-stores-wrap" class="top-vendor-container">
- <div class="wcfmmp-stores-content">
- <ul class="top-vendor-list wcfmmp-store-wrap">
- <?php
- $args = array('per_row' => 3);
- foreach ($vendor_list as $vendor_id) {
- $args['store_id'] = $vendor_id;
- $WCFMmp->template->get_template('store-lists/wcfmmp-view-store-lists-card.php', $args);
- }
- ?>
- </ul>
- </div>
- </div>
- <?php
- $list = ob_get_contents();
- ob_end_clean();
- return $list;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement