|
1 | 1 | <?php |
2 | 2 |
|
3 | | -/* 3D viewer custom fields */ |
4 | | -function add_custom_3d_checkbox_field() { |
| 3 | +/* 3D viewer custom section and fields */ |
| 4 | + |
| 5 | +// Section 3D viewer under product settings |
| 6 | +add_filter('woocommerce_product_data_tabs', 'add_3d_viewer_tab'); |
| 7 | +function add_3d_viewer_tab($tabs) { |
| 8 | + $tabs['3d_viewer_tab'] = array( |
| 9 | + 'label' => __('3D viewer', 'woocommerce'), // Etichetta della scheda |
| 10 | + 'target' => '3d_viewer_product_data', |
| 11 | + 'class' => array('show_if_simple', 'show_if_variable'), // Tipi di prodotto in cui mostrare la scheda |
| 12 | + ); |
| 13 | + return $tabs; |
| 14 | +} |
| 15 | + |
| 16 | +// add 3D viewer options |
| 17 | +add_action('woocommerce_product_data_panels', 'add_custom_3d_checkbox_fields'); |
| 18 | +function add_custom_3d_checkbox_fields() { |
| 19 | + echo '<div id="3d_viewer_product_data" class="panel woocommerce_options_panel hidden">'; |
| 20 | + |
| 21 | + // enable/disable 3D |
5 | 22 | woocommerce_wp_checkbox( array( |
6 | 23 | 'id' => '_custom_3d_checkbox', |
7 | 24 | 'label' => __('3D Viewer', 'woocommerce'), |
8 | 25 | 'description' => __('Check this box to enable the 3D viewer for this product.', 'woocommerce'), |
9 | 26 | )); |
10 | | -} |
11 | | -add_action('woocommerce_product_options_inventory_product_data', 'add_custom_3d_checkbox_field'); |
12 | 27 |
|
| 28 | + woocommerce_wp_text_input(array( |
| 29 | + 'id' => '_3d_displayid', |
| 30 | + 'label' => __('Force displayid', 'woocommerce'), |
| 31 | + 'description' => __('Enter a specific Creature displayid.', 'woocommerce'), |
| 32 | + 'desc_tip' => 'true', |
| 33 | + )); |
| 34 | + |
| 35 | + woocommerce_wp_select(array( |
| 36 | + 'id' => '_3d_race', |
| 37 | + 'label' => __('Race (optional)', 'woocommerce'), |
| 38 | + 'options' => array( |
| 39 | + '1' => __('Human', 'woocommerce'), |
| 40 | + '2' => __('Orc', 'woocommerce'), |
| 41 | + '3' => __('Dwarf', 'woocommerce'), |
| 42 | + '4' => __('Nightelf', 'woocommerce'), |
| 43 | + '5' => __('Undead', 'woocommerce'), |
| 44 | + '6' => __('Tauren', 'woocommerce'), |
| 45 | + '7' => __('Gnome', 'woocommerce'), |
| 46 | + '8' => __('Troll', 'woocommerce'), |
| 47 | + // '9' => __('Goblin', 'woocommerce'), |
| 48 | + '10' => __('Bloodelf', 'woocommerce'), |
| 49 | + '11' => __('Draenei', 'woocommerce'), |
| 50 | + '0' => __('Random', 'woocommerce'), |
| 51 | + ), |
| 52 | + )); |
| 53 | + |
| 54 | + woocommerce_wp_select(array( |
| 55 | + 'id' => '_3d_gender', |
| 56 | + 'label' => __('Gender (optional)', 'woocommerce'), |
| 57 | + 'options' => array( |
| 58 | + '2' => __('Random', 'woocommerce'), |
| 59 | + '0' => __('Male', 'woocommerce'), |
| 60 | + '1' => __('Female', 'woocommerce'), |
| 61 | + ), |
| 62 | + )); |
| 63 | + |
| 64 | + echo '</div>'; |
| 65 | +} |
13 | 66 |
|
| 67 | +add_action('woocommerce_process_product_meta', 'save_3d_checkbox_field'); |
14 | 68 | function save_3d_checkbox_field($post_id) { |
15 | 69 | $custom_checkbox = isset($_POST['_custom_3d_checkbox']) ? 'yes' : 'no'; |
16 | 70 | update_post_meta($post_id, '_custom_3d_checkbox', $custom_checkbox); |
| 71 | + |
| 72 | + $custom_text_input = isset($_POST['_3d_displayid']) ? sanitize_text_field($_POST['_3d_displayid']) : ''; |
| 73 | + update_post_meta($post_id, '_3d_displayid', $custom_text_input); |
| 74 | + |
| 75 | + $custom_select = isset($_POST['_3d_race']) ? sanitize_text_field($_POST['_3d_race']) : ''; |
| 76 | + update_post_meta($post_id, '_3d_race', $custom_select); |
| 77 | + |
| 78 | + $custom_select = isset($_POST['_3d_gender']) ? sanitize_text_field($_POST['_3d_gender']) : ''; |
| 79 | + update_post_meta($post_id, '_3d_gender', $custom_select); |
17 | 80 | } |
18 | | -add_action('woocommerce_process_product_meta', 'save_3d_checkbox_field'); |
19 | 81 | ?> |
0 commit comments