Add a drop down list to single product options
-
I am trying to figure out how to modify the singe product options so the product admin can pick from the drop down list the condition of product, i.e. new/ used.
Below is a code that allows product admin to enter the condition of product manually.
// Enabling and Displaying Fields in backend add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' ); function woo_add_custom_general_fields() { global $woocommerce, $post; echo '<div class="options_group">'; woocommerce_wp_text_input( array( // Text Field type 'id' => '_Stan', 'label' => __( 'Stan', 'woocommerce' ), 'placeholder' => 'i.e: nowa; uzywana...', 'desc_tip' => 'true', 'description' => __( 'Podaj stan plyty.', 'woocommerce' ) ) ); echo '</div>'; // Closing </div> tag HERE } // Save Fields values to database when submitted (Backend) add_action( 'woocommerce_process_product_meta', 'woo_save_custom_general_fields' ); function woo_save_custom_general_fields( $post_id ){ // Saving "Conditions" field key/value $Stan_field = $_POST['_Stan']; if( !empty( $Stan_field ) ) update_post_meta( $post_id, '_Stan', esc_attr( $Stan_field ) ); } add_action('woocommerce_single_product_summary', 'woo_display_custom_general_fields_values', 45); function woo_display_custom_general_fields_values() { global $product; echo '<p class="custom-Stan">Stan: ' . get_post_meta( $product->id, '_Stan', true ) . '</p>';
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Add a drop down list to single product options’ is closed to new replies.