Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

wordpress - Adding product category search in woocommerce plugin

I've customized a plugin as per my client's need. With the plugin he can search for a product and can see the searched product's price history. Now my client asked me to change the product search into category search. I've tried a lot but don't know how to achieve that?

here is code of product search used in the plugin file

private function show_product_history_form_handler(){

        if( isset($_POST['wsh_product_id_to_search']) ){
            $searched_ID = $_POST['wsh_product_id_to_search'];
        }

        ?>  

        <form action="<?php echo $_SERVER['PHP_SELF'] . '?page=wsh-save-history-tab' ?>" method="post">
            <h2><?php echo __('Get prices history of product', 'wsh'); ?></h2>
            <table class="form-table">
                <tbody>
                    <tr valign="top">
                        <th scope="row" class="titledesc">
                            <label for="woocommerce_price_thousand_sep">Product ID</label>
                        </th>
                        <td class="forminp forminp-text" id="wsh_autocomplete_selector">
                            <input type="hidden" class="js-example-basic-multiple" name="wsh_product_id_to_search">
                        </td>
                    </tr>
                </tbody>
            </table>
            <input class="button-large button-primary" type="submit" value="Show history" />
        </form>

        <?php

        if( !empty( $searched_ID ) ){

            $_product = wc_get_product( $searched_ID );

            if( $_product->is_type('variable') ){

                $variations = $_product->get_available_variations();

                foreach ($variations as $variation) {
                    $this->show_table_prices_history( $variation['variation_id'], $searched_ID );
                }

            } else {
                $this->show_table_prices_history( trim( $searched_ID ) );
            }

        }
    }

kindly, can anyone help me to solve this? Thanks in advance

question from:https://stackoverflow.com/questions/65949798/adding-product-category-search-in-woocommerce-plugin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...