Wordpress 插件已编辑,如何在数据库上保存自定义字段?

问题描述 投票:0回答:0

我正在使用 acf 在产品选项卡上添加一些产品自定义字段。我添加了区域。我在 Dokan 上显示这个区域,为供应商添加新产品模式。但我的问题是当我创建新产品时,我选择的区域没有保存。我需要将此产品保存在我选择的区域。

<?php
                        $regions = get_terms([
                            'hierarchical' => 1,
                            'show_option_none' => '',
                            'hide_empty' => 0,
                            'taxonomy' => 'region'
                        ]);
                        ?>
                            <label for="regions"><?php esc_html_e('Region', 'your-text-domain'); ?></label><br>
                            <select name="regions" class="dokan-form-control">
                                <option value=""><?php esc_html_e('Select Region', 'your-text-domain'); ?></option>
                                <?php foreach ($regions as $region) {
                                $parent_categories = get_terms([
                                    'taxonomy' => 'region',
                                    'hide_empty' => false,
                                    'parent' => $region->term_id
                                ]);
                                if (!empty($parent_categories)) { // check if there are any child categories
                                    ?>
                                    <?php foreach ($parent_categories as $parent_category) {
                                        $child_categories = get_terms([
                                        'taxonomy' => 'region',
                                        'hide_empty' => false,
                                        'parent' => $parent_category->term_id
                                        ]);
                                        if (!empty($child_categories)) { // check if there are any child categories
                                        ?>
                                        <optgroup label="<?php echo $parent_category->name; ?>">
                                            <?php foreach ($child_categories as $child_category) { ?>
                                            <option value="<?php echo $child_category->term_taxonomy_id; ?>" id="in-region-<?php echo $child_category->term_taxonomy_id; ?>"> <?php echo $child_category->name; ?> </option>
                                            <?php } ?>
                                        </optgroup>
                                        <?php } ?>
                                    <?php } ?>
                                <?php } ?>
                                <?php } ?>
                            </select>
                        </div>

这是我显示我在产品分类法中添加的区域的代码。但是,当我作为供应商创建新产品时,我该如何保存这些区域呢?

php wordpress vendor dokan
© www.soinside.com 2019 - 2024. All rights reserved.