49 lines
1.5 KiB
PHP
Executable file
49 lines
1.5 KiB
PHP
Executable file
<?php
|
|
|
|
/**
|
|
* Créé et configure les champs personnalisés appliqués aux Produits.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Carbon_Fields\Container;
|
|
use Carbon_Fields\Field;
|
|
|
|
function cree_champs_personnalises_produit(): void
|
|
{
|
|
Container::make('post_meta', "Product's Details")
|
|
->where('post_type', '=', 'product')
|
|
->add_fields([
|
|
// Galerie des photos Produit
|
|
Field::make('media_gallery', 'photos_colonne_gauche', __('Left Column Photos'))
|
|
->set_type(['image'])
|
|
->set_duplicates_allowed(false),
|
|
// Galerie des photos portées
|
|
Field::make('media_gallery', 'photos_colonne_droite', __('Right Column Photos'))
|
|
->set_type(['image'])
|
|
->set_duplicates_allowed(false),
|
|
// Texte des détails du Produit
|
|
Field::make('rich_text', 'haiku_details_produit', __("Product's Details")),
|
|
]);
|
|
}
|
|
|
|
function cree_champ_personnalise_commande($order): void
|
|
{
|
|
woocommerce_wp_text_input([
|
|
'id' => 'tracking_number',
|
|
'label' => 'Tracking Number:',
|
|
'value' => $order->get_meta('tracking_number'),
|
|
'wrapper_class' => 'form-field-wide',
|
|
]);
|
|
}
|
|
|
|
function maj_champ_personnalise_commande($order_id): void
|
|
{
|
|
$order = wc_get_order($order_id);
|
|
$order->update_meta_data('tracking_number', wc_clean($_POST['tracking_number']));
|
|
$order->save();
|
|
}
|
|
|
|
add_action('carbon_fields_register_fields', 'cree_champs_personnalises_produit');
|
|
add_action('woocommerce_admin_order_data_after_shipping_address', 'cree_champ_personnalise_commande');
|
|
add_action('woocommerce_process_shop_order_meta', 'maj_champ_personnalise_commande');
|