skip to Main Content

i’m working with woocommerce plugin in wordpress and i want modify the search bar (styles and html) the php that contains is thaps-search-from.php in the image you can see the directory route,

https://i.imgur.com/rTBTF3W.png

for example I want delete the button

 <button id='thaps-search-button' value="<?php echo esc_attr_x( 'Submit','submit button', 'th-advance-product-search' ); ?>" type='submit'>  

modify the file directly and this worked but

What is the correct way to do this?

2

Answers


  1. i think you ll need to copy that file to your theme folder under woocommerce folder to override it and modify it, in other words you have to create a folder called woocommerce and put that specific folder/file to it, like that if woocommerce get updated it ll not break/reset your code.

    Login or Signup to reply.
  2. First of all that is not the WooCommerce plugin that you’re working on. it’s TH Advance Product Search plugin for advanced product search.

    This plugin doesn’t have template path-based customization but it provides a filter that you can use to customize the form HTML file.

    In file https://plugins.svn.wordpress.org/th-advance-product-search/trunk/inc/thaps.php you can find this line, that gives you a hook to provide a file path, which means you can copy the file into your child theme and add a filter on this hook and return your child theme file path.

    $filename = apply_filters( 'thaps_form_path', TH_ADVANCE_PRODUCT_SEARCH_PLUGIN_PATH . '/inc/thaps-search-from.php' );
    

    First of all copy inc/thaps-search-from.php file in your child theme’s woocommerce folder, and you can make customization in this copied file.

    then you need to add this code to replace the file path.

    /**
     * Modify form file path.
     */
    add_filter(
        'thaps_form_path',
        function() {
            // return the file complete path from the woocommerce directory in which we copied the file.
            return get_stylesheet_directory() . '/woocommerce/thaps-search-from.php'
        }
    );
    

    Note: I have not tested the code so if you find any error after adding the code, please let me know what is the error I will fix the code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search