Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode('wcfm_store_categories', function($attr) {
- global $wpdb, $post;
- $store_id = '';
- if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) { $store_id = absint($attr['id']); }
- if ( !$store_id && wcfm_is_store_page() ) {
- $wcfm_store_url = wcfm_get_option( 'wcfm_store_url', 'store' );
- $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
- $store_id = 0;
- if ( !empty( $store_name ) ) {
- $store_user = get_user_by( 'slug', $store_name );
- }
- $store_id = $store_user->ID;
- }
- if( !$store_id && is_product() ) {
- $store_id = $post->post_author;
- }
- if( !$store_id && is_single() && $post && is_object( $post ) && wcfm_is_vendor( $post->post_author ) ) {
- $store_id = $post->post_author;
- }
- if( !$store_id ) return;
- $sql = $wpdb->prepare("SELECT `name` FROM {$wpdb->prefix}wcfm_store_categories AS cat
- INNER JOIN {$wpdb->prefix}wcfm_store_categories_mapping AS map ON cat.ID = map.store_category_id
- WHERE `is_active` = %d and `vendor_id` = %d", 1, $store_id);
- $store_categories = $wpdb->get_col($sql);
- if( !empty( $store_categories ) ) {
- return '<p class="store-phone"><i class="wcfmfa fa-layer-group" aria-hidden="true"></i> ' . implode(', ', $store_categories) . '</p>';
- } else {
- return '<p>No categories found for this store.</p>';
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement