• I use WordPress and Cart66 to run an online store. One of my blanks vendors has a CSV online that contains the the SKU, Description, Qty in Stock, and Custom Status.

    I’m interested in pulling out the last 2 fields of the SKU for what ever page my customer is on, so that I have an up to date quantity that can be ordered and any information on when out of stock items will be back in stock.

    I’ve searched all the ways I can think of for a plugin or hack that will do this, but so far have only found plugins that make it easier to manually load csv files, but not any that will allow the website to directly read/load the csv file from a URL.

    A while back, I wrote a little PHP script that would read a csv file from a URL and parse the data, but don’t have a clue how to integrate that into WordPress.

    Any ideas or advice would be greatly appreciated.

    Thanks,
    Alisa

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Create a function that will do the work, it can be declared in functions.php of your theme or as a simple plugin. You would call the function from whichever templates are to display the data.

    The function would use file_get_contents() or if your server has it installed, cURL to get the CSV file. Once you have the file data in PHP, you could use PHP string search functions to find the proper line and extract the needed fields. It’s also likely there is some sort of library available to handle CSV files just like there are for JSON and XML. Or simply make use of your existing script.

    Firstly you need to add function in functions.php as below

    In the below code 2 is the number of parameter passed to function and 10 is the priority in which the function is going to be executed.

    add_action( 'after_setup_theme', 'your_csv_function_name',10,2 );
    
    function your_csv_function_name(param1, param2) {
    	/* Your code comes here */
    }

    For information related to add_action visit here

    Or you can use Shortcode, to know more about it visit here

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Reading a CSV file???’ is closed to new replies.