CPT Services

<?php
/**
** Snippet Title: Services*
** Snippet ID: 198*
** Snippet type: include*
** Usage: This snippet is included in your website. You can used add_action or add_filter in this type of snippet. The code is included before WordPress hooks.*
** Generated at: 2025-06-08 21:42:59*

** @author This code snippet is generated by WPMasterToolkit*
** @link <http://portfoliowh.local/wp-admin/post.php?post=198&action=edit*>
** @since 2.9.0*

*/
function create_custom_post_type() {
// Création du CPT "Service"
$labels = array(
'name'                  => _x('Services', 'Post Type General Name', 'text_domain'),
'singular_name'         => _x('Services', 'Post Type Singular Name', 'text_domain'),
'menu_name'             => __('Services', 'text_domain'),
'name_admin_bar'        => __('Servcie', 'text_domain'),
'all_items'             => __('Tous les Services', 'text_domain'),
'add_new_item'          => __('Ajouter un nouveau service', 'text_domain'),
'edit_item'             => __('Modifier le service', 'text_domain'),
'view_item'             => __('Voir le service', 'text_domain'),
'search_items'          => __('Rechercher un service', 'text_domain'),
);
$args = array(
'label'                 => __('Service', 'text_domain'),
'description'           => __('CPT pour les services', 'text_domain'),
'labels'                => $labels,
'supports'              => array('title', 'editor', 'thumbnail', 'custom-fields'),
'hierarchical'          => false,
'public'                => true,
'show_ui'               => true,
'show_in_menu'          => true,
'menu_position'         => 5,
'menu_icon'             => 'dashicons-cart',
'show_in_admin_bar'     => true,
'show_in_nav_menus'     => true,
'can_export'            => true,
'has_archive'           => true,
'exclude_from_search'   => false,
'publicly_queryable'    => true,
'capability_type'       => 'post',
);
register_post_type('service', $args);
// Création de la taxonomie "Catégories de Services"
$tax_labels = array(
'name'                       => _x('Catégories de Services', 'taxonomy general name', 'text_domain'),
'singular_name'              => _x('Catégorie de Service', 'taxonomy singular name', 'text_domain'),
'search_items'               => __('Rechercher une Catégorie', 'text_domain'),
'all_items'                  => __('Toutes les Catégories', 'text_domain'),
'parent_item'                => __('Catégorie Parent', 'text_domain'),
'parent_item_colon'          => __('Catégorie Parent :', 'text_domain'),
'edit_item'                  => __('Modifier la Catégorie', 'text_domain'),
'update_item'                => __('Mettre à jour la Catégorie', 'text_domain'),
'add_new_item'               => __('Ajouter une Nouvelle Catégorie', 'text_domain'),
'new_item_name'              => __('Nom de la Nouvelle Catégorie', 'text_domain'),
'menu_name'                  => __('Catégories de Services', 'text_domain'),
);
$tax_args = array(
'hierarchical'          => true,
'labels'                => $tax_labels,
'show_ui'               => true,
'show_admin_column'     => true,
'query_var'             => true,
'rewrite'               => array('slug' => 'categorie-service'),
);
register_taxonomy('categorie_service', array('service'), $tax_args);
// Création de la taxonomie "Etiquettes"
$tax_etiqs = array(
'name'          => _x('Étiquettes', 'taxonomy general name', 'text _domain'),
'singular_name' => _x('Étiquette', 'taxonomy singular name', 'text _domain'),
'search_items'  => __('Rechercher une Étiquette', 'text _domain'),
'all_items'     => __('Toutes les Étiquettes', 'text _domain'),
'edit_item'     => __('Modifier les Étiquettes', 'text _domain'),
'update_items'  => __('Mettre à jour l\\'Étiquette', 'text _domain'),
'add_new_item'  => __('Ajouter une Nouvelle Étiquette', 'text_domain'),
'new_item_name' => __('Nom de la Nouvelle Étiquette', 'text_domain'),
'menu_name'     => __('Étiquettes', 'text_domain'),
);
$tax_etiq_args = array(
'hierarchical'          => true,
'labels'                => $tax_etiqs,
'show_ui'               => true,
'show_admin_column'     => true,
'query_var'             => true,
'rewrite'               => array('slug' => 'etiquette-service'),
);
register_taxonomy('etiquette_service', array('service'), $tax_etiq_args);
}
add_action('init', 'create_custom_post_type', 0);
function generate_google_form_links($post_id) {
if (get_post_type($post_id) !== 'produit') return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
// 🔹 Titre de la publication (nom de l’œuvre)
$nom_service     = get_the_title($post_id);
$type_programme = get_field('', $post_id);
$prix_programme   = get_field('', $post_id);
if (!$nom_service  || !$type_programme || !$prix_programme) return;
$nom_enc     = urlencode($nom_service);
$numero_enc  = urlencode($type_programme);
$prix_enc    = urlencode($prix_programme);
$base_url = '<https://docs.google.com/forms/d/e/1FAIpQLScs-2pmJI_L43GRAQTMkaNxmghKZZkCXLt-SJJdt8dk_kmiaA/viewform?usp=pp_url>';
$entry_nom       = 'entry.1626467793';
$entry_numero    = 'entry.493677164';
$entry_option    = 'entry.155052369';
$entry_prix      = 'entry.898933555';
$url_encadre = $base_url .
"&$entry_nom=$nom_enc" .
"&$entry_numero=$numero_enc" .
"&$entry_option=" . urlencode('Encadré') .
"&$entry_prix=$prix_enc";
$url_tirage = $base_url .
"&$entry_nom=$nom_enc" .
"&$entry_numero=$numero_enc" .
"&$entry_option=" . urlencode('Tirage seul') .
"&$entry_prix=$prix_non";
update_field('lien_commande', $url_encadre, $post_id);
update_field('lien_commande_2', $url_tirage, $post_id);
}
add_action('acf/save_post', 'generate_google_form_links', 20);
/**
** Enqueue the parent theme stylesheet.*
*/
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function create_custom_post_type() {
    // Création du CPT "Produit"
    $labels = array(
        'name'                  => _x('Produits', 'Post Type General Name', 'text_domain'),
        'singular_name'         => _x('Produit', 'Post Type Singular Name', 'text_domain'),
        'menu_name'             => __('Produits', 'text_domain'),
        'name_admin_bar'        => __('Produit', 'text_domain'),
        'all_items'             => __('Tous les Produits', 'text_domain'),
        'add_new_item'          => __('Ajouter un nouveau produit', 'text_domain'),
        'edit_item'             => __('Modifier le produit', 'text_domain'),
        'view_item'             => __('Voir le produit', 'text_domain'),
        'search_items'          => __('Rechercher un produit', 'text_domain'),
    );

    $args = array(
        'label'                 => __('Produit', 'text_domain'),
        'description'           => __('CPT pour les produits', 'text_domain'),
        'labels'                => $labels,
        'supports'              => array('title', 'editor', 'thumbnail', 'custom-fields'),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'menu_icon'             => 'dashicons-cart',
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'post',
    );
    register_post_type('produit', $args);

    // Création de la taxonomie "Catégories de Produits"
    $tax_labels = array(
        'name'                       => _x('Catégories de Produits', 'taxonomy general name', 'text_domain'),
        'singular_name'              => _x('Catégorie de Produit', 'taxonomy singular name', 'text_domain'),
        'search_items'               => __('Rechercher une Catégorie', 'text_domain'),
        'all_items'                  => __('Toutes les Catégories', 'text_domain'),
        'parent_item'                => __('Catégorie Parent', 'text_domain'),
        'parent_item_colon'          => __('Catégorie Parent :', 'text_domain'),
        'edit_item'                  => __('Modifier la Catégorie', 'text_domain'),
        'update_item'                => __('Mettre à jour la Catégorie', 'text_domain'),
        'add_new_item'               => __('Ajouter une Nouvelle Catégorie', 'text_domain'),
        'new_item_name'              => __('Nom de la Nouvelle Catégorie', 'text_domain'),
        'menu_name'                  => __('Catégories de Produits', 'text_domain'),
    );

    $tax_args = array(
        'hierarchical'          => true, // Permet d'avoir des catégories imbriquées
        'labels'                => $tax_labels,
        'show_ui'               => true,
        'show_admin_column'     => true,
        'query_var'             => true,
        'rewrite'               => array('slug' => 'categorie-produit'),
    );

    register_taxonomy('categorie_produit', array('produit'), $tax_args);
}
add_action('init', 'create_custom_post_type', 0);
function oppsys_generate_google_form_links($post_id) {
    if (get_post_type($post_id) !== 'produit') return;
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;

    // 🔹 Titre de la publication (nom de l’œuvre)
    $nom_oeuvre     = get_the_title($post_id); // Utilisation du titre WordPress
    $numero_image   = get_field('numero_image', $post_id);
    $prix_encadre   = get_field('prix_encadre', $post_id);
    $prix_tirage    = get_field('prix_non_encadre', $post_id);

    if (!$nom_oeuvre || !$numero_image || !$prix_encadre || !$prix_tirage) return;

    $nom_enc     = urlencode($nom_oeuvre);
    $numero_enc  = urlencode($numero_image);
    $prix_enc    = urlencode($prix_encadre);
    $prix_non    = urlencode($prix_tirage);

    $base_url = '<https://docs.google.com/forms/d/e/1FAIpQLScs-2pmJI_L43GRAQTMkaNxmghKZZkCXLt-SJJdt8dk_kmiaA/viewform?usp=pp_url>';

    $entry_nom       = 'entry.1626467793';
    $entry_numero    = 'entry.493677164';
    $entry_option    = 'entry.155052369';
    $entry_prix      = 'entry.898933555';

    $url_encadre = $base_url .
        "&$entry_nom=$nom_enc" .
        "&$entry_numero=$numero_enc" .
        "&$entry_option=" . urlencode('Encadré') .
        "&$entry_prix=$prix_enc";

    $url_tirage = $base_url .
        "&$entry_nom=$nom_enc" .
        "&$entry_numero=$numero_enc" .
        "&$entry_option=" . urlencode('Tirage seul') .
        "&$entry_prix=$prix_non";

    update_field('lien_commande', $url_encadre, $post_id);
    update_field('lien_commande_2', $url_tirage, $post_id);
}
add_action('acf/save_post', 'oppsys_generate_google_form_links', 20);

google form

CPT produits