Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode('wcfm_vendors_by_product', function($attr) {
- global $wpdb;
- if ( empty( $attr['id'] ) || ! absint( $attr['id'] ) ) return '';
- $product_id = absint( $attr['id'] );
- $product = wc_get_product($product_id);
- if(!$product) return '';
- $vendor_id = wcfm_get_vendor_id_by_post($product_id);
- if(!apply_filters( 'wcfm_is_allow_product_multivendor_title_edit_disable', true )) return $vendor_id;
- $multi_parent_id = get_post_meta( $product_id, '_is_multi_parent', true );
- if(!$multi_parent_id) {
- $multi_parent_id = get_post_meta( $product_id, '_has_multi_selling', true );
- }
- if(!$multi_parent_id) return $vendor_id;
- $sql = "SELECT GROUP_CONCAT(vendor_id) as vendors FROM `{$wpdb->prefix}wcfm_marketplace_product_multivendor` WHERE `parent_product_id` = $multi_parent_id";
- $results = $wpdb->get_row( $sql );
- $vendor_list = isset($results->vendors) ? explode(',', $results->vendors) : array();
- if(wcfm_is_vendor($vendor_id) && !in_array($vendor_id, $vendor_list)) {
- array_unshift($vendor_list, $vendor_id);
- }
- return implode(', ', $vendor_list);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement