Comment puis-je modifier le texte du bouton de “Choisir une option” dans le Thème?

Comment pourrais-je aller sur la modification de ce code PHP pour changer de Choisir une option en fonction de l'id de l'élément select dans le Thème plugin pour WordPress? Je crois avoir trouvé le bon fichier PHP dans wc-template-function.php mais mon manque de compétences en PHP qui me retient. Voici ce que j'ai à ce jour:

if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
/**
* Output a list of variation attributes for use in the cart forms.
*
* @param array $args
* @since 2.4.0
*/
function wc_dropdown_variation_attribute_options( $args = array() ) {
$args = wp_parse_args( $args, array(
'options'          => false,
'attribute'        => false,
'product'          => false,
'selected'         => false,
'name'             => '',
'id'               => '',
'class'            => '',
'show_option_none' => __( 'Choose an option', 'woocommerce' ),
'show_option_color' => __( 'Choose a color', 'woocommerce' ),
'show_option_size' => __( 'Choose a size', 'woocommerce' )
) );
$options   = $args['options'];
$product   = $args['product'];
$attribute = $args['attribute'];
$name      = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
$id        = $args['id'] ? $args['id'] : sanitize_title( $attribute );
$class     = $args['class'];
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
$attributes = $product->get_variation_attributes();
$options    = $attributes[ $attribute ];
}
echo '<select id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . '" name="' . esc_attr( $name ) . '" data-attribute_name="attribute_' . esc_attr( sanitize_title( $attribute ) ) . '">';
if ( $args['show_option_none'] ) {
echo '<option value="">' . esc_html( $args['show_option_none'] ) . '</option>';
}
if ( $args['$id_colors'] ) {
echo '<option value="">' . esc_html( $args['show_option_color'] ) . '</option>';
}
if ( $args['$id_sizes'] ) {
echo '<option value="">' . esc_html( $args['show_option_size'] ) . '</option>';
}
if ( ! empty( $options ) ) {
if ( $product && taxonomy_exists( $attribute ) ) {
//Get terms if this is a taxonomy - ordered. We need the names too.
$terms = wc_get_product_terms( $product->id, $attribute, array( 'fields' => 'all' ) );
foreach ( $terms as $term ) {
if ( in_array( $term->slug, $options ) ) {
echo '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . apply_filters( 'woocommerce_variation_option_name', $term->name ) . '</option>';
}
}
} else {
foreach ( $options as $option ) {
//This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
$selected = sanitize_title( $args['selected'] ) === $args['selected'] ? selected( $args['selected'], sanitize_title( $option ), false ) : selected( $args['selected'], $option, false );
echo '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
}
}
}
echo '</select>';
}
}

Vous pouvez voir où j'ai essayé d'ajouter show_option_color et show_option_size dans le tableau pour les ajouter, en cas de déclarations pour eux, mais il ne semble pas fonctionner. Je ne suis pas sûr de la façon de référence à l'id de l'élément select et écrire l'instruction if en fonction de si son est correct sélectionner l'élément.

Voici le code HTML que je suis en train de cible.

<select id="sizes" class="" name="attribute_sizes" data-attribute_name="attribute_sizes">Want this to say Choose a size</select>
<select id="colors" class="" name="attribute_sizes" data-attribute_name="attribute_sizes">Want this to say Choose a color</select>

variable.php les lignes de code 27 - 38:

<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
<td class="value">
<?php
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
echo end( $attribute_keys ) === $attribute_name ? '<a class="reset_variations" href="#">' . __( 'Clear selection', 'woocommerce' ) . '</a>' : '';
?>
</td>
</tr>
<?php endforeach;?>
Pouvez-vous préciser cette partie? "Choisir une option basée sur l'id de la dans la" vouliez-vous dire en fonction de l'id du produit?
Assurez-vous. Chaque produit a aucune option pour sélectionner à partir de, sélectionnez une option de taille, sélectionnez une option de couleur, ou les deux options. Cependant, au lieu de dire sélectionnez une taille ou sélectionnez une couleur, ils ont tous simplement dire "Choisissez une option". Je veux juste que chacun-à-dire de choisir une couleur ou Sélectionnez une taille en fonction de ce que vous êtes en fait la sélection. L'sélectionner une couleur, les boutons ont un id de #couleurs et sélectionnez une taille boutons ont un id de #tailles, mais le texte d'affichage pour les deux dit "Choisissez une option. Espérons que cela clarifie.
Oui, ça aide. Chercher une réponse sous peu!

OriginalL'auteur jfoutch | 2015-08-23