WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
Getting data from Woocommerce Page (3 posts)

  1. jcyin
    Member
    Posted 1 year ago #

    Using this plugin I'm able to get information such as titles and published dates from a normal page. However when I try this on a product page created using Woocommerce information such as price or others are not visible and cannot be retrieved. Is there a way round for this?

    Thanks

    http://wordpress.org/extend/plugins/json-api/

  2. bheadrick
    Member
    Posted 1 year ago #

    that's because the default json get_post simply returns the post object, but you need the product object. I think you need to create a new controller for that.

    example: http://wordpress.org/support/topic/plugin-json-api-added-a-custom-controller-for-querying-wordpress-options?replies=4

  3. chrisonhismac
    Member
    Posted 1 year ago #

    I changed the function called set_custom_fields_value in models->post.php to the following.

    Now if you add ?json=1&custom_fields=all after the url it will return ALL custom values including woo data - make sure you want all the field returned!

    function set_custom_fields_value() {
        global $json_api;
        if ($json_api->include_value('custom_fields') &&
            $json_api->query->custom_fields) {
          if($json_api->query->custom_fields == 'all') {
            $wp_custom_fields = get_post_custom($this->id);
            $this->custom_fields = new stdClass();
            foreach ( $wp_custom_fields as $key => $value ){
              $this->custom_fields->$key = $value;
            }
          } else {
            $keys = explode(',', $json_api->query->custom_fields);
            $wp_custom_fields = get_post_custom($this->id);
            $this->custom_fields = new stdClass();
            foreach ($keys as $key) {
              if (isset($wp_custom_fields[$key])) {
                $this->custom_fields->$key = $wp_custom_fields[$key];
              }
            }
          }
        } else {
          unset($this->custom_fields);
        }
      }

    [Please post code between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic