$tabs Onglets existants. * @return array */ public function add_tab( array $tabs ): array { $tabs['agec_ready'] = array( 'label' => __( 'AGEC', 'agec-ready' ), 'target' => 'agec_ready_product_data', 'priority' => 80, 'class' => array(), ); return $tabs; } public function render_panel(): void { global $post; $product = $post ? wc_get_product( $post->ID ) : null; if ( ! $product instanceof \WC_Product ) { return; } $triman = (bool) $product->get_meta( Meta::PRODUCT_TRIMAN ); $components = (array) $product->get_meta( Meta::PRODUCT_INFOTRI ); echo '
'; wp_nonce_field( self::NONCE_ACTION, self::NONCE_NAME ); woocommerce_wp_checkbox( array( 'id' => '_agec_triman', 'label' => __( 'Signalétique Triman', 'agec-ready' ), 'description' => __( 'Afficher le Triman et les consignes de tri sur la fiche produit.', 'agec-ready' ), 'value' => $triman ? 'yes' : 'no', ) ); echo '
'; echo '

' . esc_html__( 'Consignes de tri par matériau', 'agec-ready' ) . '

'; foreach ( InfoTri::materials() as $material => $label ) { woocommerce_wp_select( array( 'id' => '_agec_infotri_' . $material, 'name' => '_agec_infotri[' . $material . ']', 'label' => $label, 'options' => InfoTri::consigne_options_for( $material ), 'value' => isset( $components[ $material ] ) ? $components[ $material ] : '', ) ); } echo '
'; echo '
'; } /** * Sauvegarde des champs AGEC sur l'objet produit. * * @param \WC_Product $product Produit en cours de sauvegarde. */ public function save( \WC_Product $product ): void { if ( ! isset( $_POST[ self::NONCE_NAME ] ) ) { return; } $nonce = sanitize_text_field( wp_unslash( $_POST[ self::NONCE_NAME ] ) ); if ( ! wp_verify_nonce( $nonce, self::NONCE_ACTION ) ) { return; } // Défense en profondeur (SEC-1) : on n'écrit la meta que si l'utilisateur peut éditer CE produit, // sans dépendre du contexte d'appel WooCommerce (le hook pourrait être déclenché par un tiers). if ( ! current_user_can( 'edit_product', $product->get_id() ) ) { return; } $triman = isset( $_POST['_agec_triman'] ) && 'yes' === sanitize_text_field( wp_unslash( $_POST['_agec_triman'] ) ); $product->update_meta_data( Meta::PRODUCT_TRIMAN, $triman ? 1 : 0 ); $raw = isset( $_POST['_agec_infotri'] ) && is_array( $_POST['_agec_infotri'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['_agec_infotri'] ) ) : array(); $components = InfoTri::sanitize_components( $raw ); $product->update_meta_data( Meta::PRODUCT_INFOTRI, $components ); } }