Skip to content

Conversation

masteradhoc
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

WooCommerce Core is getting the Cost of Goods Sold (COGS) feature soon. (currently behind a feature flag)
We should allow to also auto generate COGS Values inside Smooth Generator.
Approach automatically generates it for simple and variable products while deducting a random 15-60% from the regular price

Closes #175 .

How to test the changes in this Pull Request:

  1. activate the COGS feature at /wp-admin/admin.php?page=wc-settings&tab=advanced&section=features if not yet done
  2. apply this PR
  3. generate 25 random products
  4. check for simple and variable products if the COGS number was generated correctly

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Changelog entry

implement cost of good sold (cogs) generation

Enter a summary of all changes on this Pull Request. This will appear in the changelog if accepted.

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@layoutd layoutd self-assigned this Oct 2, 2025
@layoutd layoutd requested review from Copilot and layoutd and removed request for Copilot October 2, 2025 22:15
Copy link
Contributor

@layoutd layoutd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this! A few observations:

  • If the store has COGS disabled, a notice is shown for each product that's created:
    Notice: Function WC_Product::set_cogs_value was called <strong>incorrectly</strong>. The Cost of Goods sold feature is disabled, thus the method called will do nothing and will return dummy data. Backtrace: … wc_doing_it_wrong Please see <a href="https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 9.5.0.) in /var/www/html/wp-includes/functions.php on line 6121

    Maybe conditionally setting the value using ( wc_get_container()->get( 'Automattic\WooCommerce\Internal\CostOfGoodsSold\CostOfGoodsSoldController' )->feature_is_enabled() ) would make sense?

  • The variable products also have a default COGS value (even if all the variants also have one set). Would it make sense to set it to some % of the lowest variant's price?

  • Finally, would it make sense to have some products generate with no COGS (not set, or 0)?

@masteradhoc
Copy link
Contributor Author

masteradhoc commented Oct 7, 2025

Thanks @layoutd!

If the store has COGS disabled, a notice is shown for each product that's created:
Notice: Function WC_Product::set_cogs_value was called incorrectly. The Cost of Goods sold feature is disabled, thus the method called will do nothing and will return dummy data. Backtrace: … wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 9.5.0.) in /var/www/html/wp-includes/functions.php on line 6121

Maybe conditionally setting the value using ( wc_get_container()->get( 'Automattic\WooCommerce\Internal\CostOfGoodsSold\CostOfGoodsSoldController' )->feature_is_enabled() ) would make sense?

As COGS will be in released to core in V10.3 (without the need to activate it i assume) the first point should be covered. The Core Release is in two weeks, i guess we'll probably aim for a later SmoothGenerator release anyway.

The variable products also have a default COGS value (even if all the variants also have one set). Would it make sense to set it to some % of the lowest variant's price?
Thats a really good point. As far as i've tested the default COGS Value for variable products only serves as a default for variations. So basically even if we dont set anything on a variation if the COGS value on the variable product is set the variation will have this value.

Finally, would it make sense to have some products generate with no COGS (not set, or 0)?
Which brings us to this question. As for the moment we mostly assign values and dont leave values empty i didnt though of a solution here. Probably i think that would be a great idea to open a separate issue and see which fields would be suitable for keeping empty sometimes. What do you think?

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.

[Enhancement]: Implement COGS

2 participants