Advertisement
palsushobhan

wcfm_all_vendors_selling_a_given_product

Jan 6th, 2025
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. add_shortcode('wcfm_vendors_by_product', function($attr) {
  2.     global $wpdb;
  3.     if ( empty( $attr['id'] ) || ! absint( $attr['id'] ) ) return '';
  4.     $product_id = absint( $attr['id'] );
  5.     $product = wc_get_product($product_id);
  6.     if(!$product) return '';
  7.     $vendor_id = wcfm_get_vendor_id_by_post($product_id);
  8.     if(!apply_filters( 'wcfm_is_allow_product_multivendor_title_edit_disable', true )) return $vendor_id;
  9.     $multi_parent_id = get_post_meta( $product_id, '_is_multi_parent', true );
  10.     if(!$multi_parent_id) {
  11.         $multi_parent_id = get_post_meta( $product_id, '_has_multi_selling', true );
  12.     }
  13.     if(!$multi_parent_id) return $vendor_id;
  14.    
  15.     $sql = "SELECT GROUP_CONCAT(vendor_id) as vendors FROM `{$wpdb->prefix}wcfm_marketplace_product_multivendor` WHERE `parent_product_id` = $multi_parent_id";
  16.     $results = $wpdb->get_row( $sql );
  17.     $vendor_list = isset($results->vendors) ? explode(',', $results->vendors) : array();
  18.     if(wcfm_is_vendor($vendor_id) && !in_array($vendor_id, $vendor_list)) {
  19.         array_unshift($vendor_list, $vendor_id);
  20.     }
  21.     return implode(', ', $vendor_list);
  22. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement