MarketPress inventory

Hi, I use Square for my POS in retail and MarketPress on my website. Basically, using Squares API I would like to manipulate my MarketPress inventory every time a sale is made via Square. I was wondering what the best way to access the MarketPress inventory? Cheers Cam

  • Panos

    Hi Cameron ,

    Sorry for such late reply!

    This is a very interesting request but it is not that simple to accomplish. I will try to provide guidance which you can use as your base.

    The goal is to update a product meta fields for inventory and also for soled items in the db. Specifically these meta fields are inventory and mp_sales_count.

    The preferred way is by using the WP REST API but it would require allot of reading to create the appropriate custom routes and endpoints required.

    Instead I could drive you through a different way by using a custom plugin as you basis. Please download custom plugin from:

    You can install it as a normal plugin and activate it.

    You can then create a page on your site where you have your MarketPress installation and go to it's page attributes and select the page template MP Remote Inventory and leave the content empty.

    I don't know how you retrieve your information from your payment gateway, but you will need the products ids and the quantity for each.

    So you'll need to create a request ( eg curl or even with ajax ) where you need to provide:

    1. the url of the page you created and uses the MP Remote Inventory template

    2. in the url you will need to include the following query vars:
    username by default you can use wpmudev
    keyby default !rand0mP@5s
    and the products_quantities which will be a json string containing product ids and quantities.

    If you have a different WordPress site you can add the following in your functions.php:

    add_action( 'wp_head', function(){
    	$products_qts = array(
    		97 => 2,
    		33 => 4
    	$page_url = '';
    	$username = 'wpmudev';
    	$key = 		'!rand0mP@5s';
    	$products_qts = json_encode( $products_qts );
    	$wp_request_url =$page_url . '?username=' . $username . '&key=' . $key . '&products_quantities=' . $products_qts;
    	$wp_request_post_response = wp_remote_request(
    	        'method'    => 'GET',
    }, 10 );

    You will need to replace the product ids and quantities and replace the url and query strings explained above.

    I would strongly suggest to change the username and key used by modifying plugin file
    at lines 38 and 39.

    Hope this helps!


  • Panos

    Hi Cameron ,

    So sorry for taking so long to get back to you :slight_frown:

    I have created a simple custom route which you can find it here:

    Upload file to your site's mu-plugins folder (wp-content/mu-plugins - if it doesn't exist you can create it).

    From a different site you can do a new request for:

    '' . $products_quantities_json;

    Here is an example using wp_remote_request:

    $wp_request_headers = array(
    	    'Authorization' => 'Basic ' . base64_encode( 'panos:1234567890' )
    	$products_quantities = json_encode( array(
    			'97' => 2,
    			'33' => 1
    		) );
    	$wp_request_url = '' . $products_quantities;
    	$wp_request_post_response = wp_remote_request(
    	        'method'    => 'GET',
    	        'headers'   => $wp_request_headers
    	$response_code = wp_remote_retrieve_response_code( $wp_request_post_response ) . ' ' . wp_remote_retrieve_response_message( $wp_request_post_response );
    	$response = $wp_request_post_response;

    You need to replace the username:password and the

    The $products_quantities should contain a json listing product_id => amount to subtract.

    Please let me know if something is not clear :slight_smile:


  • Panos

    Hi Cameron ,

    If I understand correctly you need to be able to see the variation id in the products page in admin right?

    If so could you try adding the following snippet in a mu-plugin:

    add_action( 'admin_footer', function(){
        $screen = get_current_screen();
        if( ! isset( $screen->post_type ) || $screen->post_type != MP_Product::get_post_type() ){
        <script type="text/javascript">
                    $( '.mp_variations_table_box table tbody#the-list tr' ).each(function(){
                        var variation_id = $(this).data( 'id' );
                        var field = $( this ).find( 'td:eq( 0 )' );
                        field.append( '<span style="display:block;">( ' +variation_id + ' )</span>' );
    }, 10 );

    It should add the id right under the variation's image.