I use Woocommerce and I created a selection window in the admin panel. I fill in the information in the selection box through a flat file. Everything is working fine (almost).
The part that I'm stuck on, after choosing the "choice" I want and save. I get an array , not the actual one . I'm close, but I just can't put it on her. $key $value
Update: here is my full 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">';
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' );
function woo_add_custom_general_fields_save( $post_id ){
$woocommerce_text_field = $_POST['_pet_name'];
if( !empty( $woocommerce_text_field ) )
update_post_meta( $post_id, '_pet_name', esc_attr( $woocommerce_text_field ) );
$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' );
My breed.txt file contains 3 lines (elements):
Please Select a breed...
Abyssinian
Affenpinscher
And the generated array looks like this:
Array (
[0] => Please Select a breed...
[1] => Abyssinian
[2] => Affenpinscher
)
So when I select , I get the value instead . "Affenpinscher" "2" "Affenpinscher"
What am I doing wrong? How can I solve this problem?
thank