• 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/

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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

    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.]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting data from Woocommerce Page’ is closed to new replies.