• Can someone please explain to me how I can pull the products for my Woocommerce store from an external database?

    What I am trying to do is pull the products from our point of sale system (which uses Microsoft SQL Server) and display them on my online store (which is WordPress so it uses MySQL obviously) so that the two are always in sync (such as product titles, prices, stock quantity, etc.)

    I don’t think it’s possible to pull it directly from the Microsoft SQL Server database since WordPress probably won’t understand it. I was considering developing an API that could convert the Microsoft SQL Server to MySQL and then use that database for my site. Is this even possible?

    And once I get the converted MySQL database, how do I connect my site to it and pull my products from there?

    I know that products are stored in the table wp_posts but that seems to be a very complicated table. I need the table to have simple columns such as title, price, image link, quantity, etc.

    I appreciate anyone’s help.

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

    (@bcworkz)

    There is a mssql module available for PHP, but it’s unlikely to be installed by default. You could ask your host to configure your PHP to include it so you can talk to the MS SQL Server from PHP. That allows you to get the data, but WooCommerce will have no idea how to handle such data, it’s built around WP post types. You would need a completely customized fork of WC that is rewritten to use MS Server and whatever data schema your POS uses. It would end up being a major coding project.

    More feasible IMO would be to develop some sort of nightly data import routine that copies the POS data and translates it into WP post types that WC can understand. You wouldn’t be out of sync for more than 24 hours and most data would likely remain valid. You could not get “simple columns” this way, but you also do not need to rewrite WC.

    Thread Starter arshadndt

    (@arshadndt)

    Thanks for your answer.

    But could you elaborate more on

    More feasible IMO would be to develop some sort of nightly data import routine that copies the POS data and translates it into WP post types that WC can understand.

    Moderator bcworkz

    (@bcworkz)

    You can setup WP to execute any arbitrary PHP function on a recurring basis. The function could first make a backup of the relevant WP DB tables for safety’s sake. It would then delete all existing product data and rebuild a fresh, up to date set from the POS data. The function would transform the POS data into a format that WC can understand and insert it into the WP DB.

    This would still entail a lot of custom coding, but IMO it’s much preferable to rewriting WC to work directly off the POS data.

    arshadndt Do you find good way about this to work good?

    Hi, If you can export a xml or csv with your products, I think you can take a look to plugin wp All import plus wp All import woocomerce addon and maybe advanced custom fields addon If you need. With this plugin you will be able to import every field of your products, update them too and schedule importations. But you have to be able to export your database in xml or csv utf-8 codification and take care inside your fields there are not hidden end of line special characters \n.
    Hope it helps.

    There is a MySQL module available for PHP, but it’s not likely to be established by way of default. You ought to ask your host to configure your PHP to include it so you can talk to the MS SQL Server from PHP. That lets in you to get the statistics, however, WooCommerce will have no idea a way to handle such information, it’s built around WP put up sorts. You could need a completely customized fork of WC that is rewritten to apply MS Server and whatever information schema your POS makes use of. It could come to be being a chief coding undertaking.

    I think you’re looking to use WordPress’s REST API. This is something I have been researching as well.

    Below is WooCommerce’s REST API documentation:

    https://woocommerce.github.io/woocommerce-rest-api-docs/

    You can build an intermediary app in php, node, etc to pull your data and push it to WooCommerce with REST and JSON

    An example would be as below for a batch update:
    Note: You would of course have to code “pulling” your data into a json format that suits “pushing” and is beyond the scope of what I’m trying to explain. This is by no means an exhaustive tutorial. Hope it gives you an idea on how to get started. I’m still figuring this out myself! ??

    Source: WooCommerce – Batch Update Products – REST

    <?php
    $data = [
        'create' => [
            [
                'name' => 'Woo Single #1',
                'type' => 'simple',
                'regular_price' => '21.99',
                'virtual' => true,
                'downloadable' => true,
                'downloads' => [
                    [
                        'name' => 'Woo Single',
                        'file' => 'https://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg'
                    ]
                ],
                'categories' => [
                    [
                        'id' => 11
                    ],
                    [
                        'id' => 13
                    ]
                ],
                'images' => [
                    [
                        'src' => 'https://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg'
                    ]
                ]
            ],
            [
                'name' => 'New Premium Quality',
                'type' => 'simple',
                'regular_price' => '21.99',
                'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
                'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
                'categories' => [
                    [
                        'id' => 9
                    ],
                    [
                        'id' => 14
                    ]
                ],
                'images' => [
                    [
                        'src' => 'https://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg'
                    ],
                    [
                        'src' => 'https://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg'
                    ]
                ]
            ]
        ],
        'update' => [
            [
                'id' => 799,
                'default_attributes' => [
                    [
                        'id' => 6,
                        'name' => 'Color,
                        'option' => 'Green'
                    ],
                    [
                        'id' => 0,
                        'name' => 'Size',
                        'option' => 'M'
                    ]
                ]
            ]
        ],
        'delete' => [
            794
        ]
    ];
    
    print_r($woocommerce->post('products/batch', $data));
    ?>
    
    • This reply was modified 4 years, 12 months ago by vinayvidyasagar. Reason: Added WooCommerce API Resource links and example
    • This reply was modified 4 years, 12 months ago by vinayvidyasagar.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to pull woocommerce products from an external database’ is closed to new replies.