WOOT - WooCommerce Active Products Tables

Spalte mit benutzerdefinierten Meta-Feldern im Popup hinzufügen

Ein Beispiel für eine solche Spalte sehen Sie auf dieser Seite: https://demo.products-tables.com/audio-referrals/

So gehen Sie vor:

  • Öffnen Sie die Datei functions.php des aktuellen WordPress-Themes
  • Fügen Sie den folgenden Code hinzu:
    add_action('woot_profile_extend', function($profile, $action_name) {
    
        if ($action_name === 'woot_woocommerce_tables') {
         
            //for https://demo.products-tables.com/audio-referrals/
            $profile['sound_options'] = [
                'title' => esc_html('Sound options', 'woocommerce-products-tables'),
                'order' => FALSE,
                'action' => function($post_id) {
                    return do_shortcode("[woot_single_btn id={$post_id} button_text='Options' columns='sound_bitrate,sound_duration,sound_year,sound_artist,sound_info' css_class='woot-btn' help_title='How to add column Options' help_link='https://products-tables.com/how-to-add-column-with-custom-meta-fields-in-popup/']");
                }
            ];
        }
    
        return $profile;
    }, 10, 2);
    
  • Registrieren Sie die benötigten Meta-Felder per Code im WOOT-System:
    //add custom meta fields not visible on WOOT admin page to select it in sound options
    add_action('woot_profile_extend', function($profile, $action_name) {
    
        $sound_keys = [
            'sound_bitrate' => 'Bitrate (kbps)',
            'sound_duration' => 'Duration',
            'sound_year' => 'Year',
            'sound_artist' => 'Artist',
            'sound_info' => 'Info',
        ];
    
        foreach ($sound_keys as $key => $title) {
            $profile[$key] = [
                'title' => $title,
                'order' => 'asc',
                'display' => false, //do not display in fields list on WOOT backend
                'action' => function($post_id) use($key) {
                    return get_post_meta($post_id, $key, true);
                }
            ];
        }
    
        return $profile;
    }, 10, 2);
    
  • Legen Sie in der Tabelle, in der die Spalte „Options“ angezeigt werden soll, eine neue Spalte (Column) an, benennen Sie sie und wählen Sie das Feld 'Sound options' aus

Auf diese Weise können Sie Popups für beliebige Produktarten Ihres Shops erstellen.