WOOT - WooCommerce Active Products Tables

Comment ajouter une colonne de champs meta personnalisés dans une popup

Vous pouvez voir un exemple de ce type de colonne sur cette page : https://demo.products-tables.com/audio-referrals/

Procédez comme suit :

  • Ouvrez le fichier functions.php du thème WordPress actif
  • Ajoutez le code suivant :
    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);
    
  • Enregistrez les champs meta nécessaires dans le système WOOT par code :
    //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);
    
  • Dans le tableau où vous voulez afficher la colonne « Options », créez une nouvelle colonne, donnez-lui un nom et sélectionnez le champ 'Sound options'

De cette façon, vous pouvez créer des popups pour tous les types de produits de votre boutique.