2016-01-07 1 views
0

aide, j'ai utilisé woo-commerce et je suis capable d'afficher les variations sur shop/archive. Ce que veut mon client, c'est de changer le titre/nom pour chaque variation qui n'a pas d'arrière-plan. ses seuls sku, images, etc. AUCUN titre. Comment puis-je ajouter un champ pour le titre?Woocommerce variation titre éditeur admin

Screenshot here

+0

Ok je résous déjà. en utilisant ceci: woocommerce_product_after_variable_attributes & woocommerce_save_product_variation avec meta personnalisé. –

+0

Vous pouvez ajouter une réponse à votre propre question. ça pourrait aider quelqu'un d'autre –

Répondre

0

Vous pouvez le faire en ajoutant HTML personnalisé dans l'action woocommerce_product_after_variable_attributes

add_action('woocommerce_product_after_variable_attributes', function($loop, $variation_data, $variation) { ?> 
    <div> 
     <p class="form-row form-row-full"> 
      <label>Variation Title</label> 
      <input type="text" name="variable_post_title[<?php echo $loop; ?>]" value="<?php echo esc_attr($variation->post_title); ?>" placeholder="Variation title"> 
     </p> 
    </div><?php 
}, 10, 3); 

puis enregistrez le titre du poste dans woocommerce_save_product_variation

add_action('woocommerce_save_product_variation', function() { 
    if ('variable' !== $_POST['product-type']) { 
     return; 
    } 

    if (! isset($_POST['variable_post_title'][ $i ])) { 
     return; 
    } 

    $variation_post_title = wc_clean($_POST['variable_post_title'][ $i ]); 

    wp_update_post([ 
     'ID' => $variation_id, 
     'post_title' => $variation_post_title, 
    ]); 

    clean_post_cache($variation_id); 
}, 10, 2);