I einem WooCommerce verwenden und ich habe eine Auswahlbox in dem Admin-Panel gebaut. Ich fülle die Informationen in der Auswahlbox über eine flache Datei. Alles funktioniert gut (fast).WooCommerce - Abrufen des korrekten Datenwertes für Auswahlbox nach
Der Teil steckte ich bin eingeschaltet ist, nachdem ich die „Wahl“ wählen Ich will und das speichern Ich erhalte die Array $key
Position und nicht die tatsächliche $value
. Ich bin nah dran, aber ich kann es nicht genau sagen.
Update: Hier ist meine vollständige Code:
function woo_add_custom_admin_product_tab() {
?>
<li class="custom_tab"><a href="#custom_tab_data"><?php _e('Additional Information', 'woocommerce'); ?></a></li>
<?php
}
add_action('woocommerce_product_write_panel_tabs', 'woo_add_custom_admin_product_tab');
function woo_add_custom_admin_fields() {
global $woocommerce, $post;
echo '<div id="custom_tab_data" class="panel woocommerce_options_panel">';
echo '<div class="options_group">';
// Select - Breed1
if (file_exists (plugin_dir_path(__FILE__) .'breed.txt')) {
$breedData = file_get_contents (plugin_dir_path(__FILE__) .'breed.txt');
$breedArray = explode ("\n", $breedData);
}
woocommerce_wp_select(array(
'id' => '_select_breed1',
'label' => __('Select Primary Breed', 'woocommerce'),
'desc_tip' => 'true',
'description' => __('Select the primary breed of the pet.', 'woocommerce'),
'options' => $breedArray
));
echo '</div>';
echo '</div>';
}
add_action('woocommerce_product_write_panels', 'woo_add_custom_admin_fields');
// Save Fields;
function woo_add_custom_general_fields_save($post_id){
// Text Field - Pet Name
$woocommerce_text_field = $_POST['_pet_name'];
if(!empty($woocommerce_text_field))
update_post_meta($post_id, '_pet_name', esc_attr($woocommerce_text_field));
// Select Field - Breed
$woocommerce_select = $_POST['_select_breed1'];
if(!empty($woocommerce_select))
update_post_meta($post_id, '_select_breed1', esc_attr($woocommerce_select));
}
add_action('woocommerce_process_product_meta', 'woo_add_custom_general_fields_save');
Meine breed.txt Datei enthält 3 Zeilen (Artikel):
Please Select a breed...
Abyssinian
Affenpinscher
Und das erzeugte Array sieht wie folgt aus:
Array (
[0] => Please Select a breed...
[1] => Abyssinian
[2] => Affenpinscher
)
Also, wenn ich "Affenpinscher"
zum Beispiel wählen, I erhalten als Wert "2"
statt "Affenpinscher"
.
Was mache ich falsch? Wie kann ich dieses Problem lösen?
Dank
Ihr Array nichts mit einer flachen Datei zu tun hat, sollten Sie diese Frage umbenennen. – Devon