Skip to content

Conversation

Nikita20010
Copy link

Overview

This PR adds a dateModified field to all WooCommerce product types in the WPGraphQL schema, including:

  • SimpleProduct
  • VariableProduct
  • ExternalProduct
  • GroupProduct
  • UnsupportedProduct

The dateModified field returns the last modified date of the product in GMT (ISO8601 format).

Motivation

Currently, there is no dateModified field available in the GraphQL schema for WooCommerce products. Adding this field enables developers to query products and get the last modified date directly via GraphQL.

Implementation

  • Added dateModified field to all product types in class-product-types.php.
  • The field uses the product model's get_date_modified() method and returns the date in ISO8601 format.
  • Works with inline fragments on the ProductUnion type.

Example Query (GraphiQL)

{
  products(first: 3) {
    nodes {
      id
      name
      ... on SimpleProduct {
        dateModified
      }
      ... on VariableProduct {
        dateModified
      }
      ... on ExternalProduct {
        dateModified
      }
      ... on GroupProduct {
        dateModified
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant