Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add woocommerce_attributes_saved trigger. Closes #35004. #36943

Conversation

helgatheviking
Copy link
Contributor

@helgatheviking helgatheviking commented Feb 23, 2023

All Submissions:

Changes proposed in this Pull Request:

Introduce woocommerce_attributes_saved trigger in admin metabox. Explanation in #35004.

Closes #35004.

How to test the changes in this Pull Request:

Setup:

  • After checking out this branch, start by recompiling legacy assets: pnpm run --filter='woocommerce/client/legacy' build.
  • When you open the product editor, be sure to clear your browser's cache so that the new JS is picked up.

This change results in a new browser event being triggered: this is for the benefit of 3PDs and nothing in WooCommerce Core takes advantage of it at present, therefore there isn't really anything tangible to test. So, our first goal should simply be to confirm we have not accidentally broken anything in the product editor:

  • Check you can update and then save changes to products.
  • Specifically, ensure you can modify and save changes to product attributes.

product-editor-metabox-attributes

Optionally, we can also perform some further tests to make sure the new event is available to 3PDs. Start by adding the following code (I suggest to a location such as wp-content/mu-plugins/test-pr-36943.php which you can remove after testing):

<?php

add_action( 'admin_footer', function () {
	echo "
		<script>
			jQuery( document.body ).on( 'woocommerce_attributes_saved', function() {
				alert( 'New event \"woocommerce_attributes_saved\" was triggered.' );
			} );
		</script>
	";
} );

With that in place:

  • Refresh the product editor.
  • Modify some product attributes, then click on the Save Attributes button.
  • You should see an alert, as in the following screenshot.

alert

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 created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?
  • Have you included testing instructions?

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.

@codecov
Copy link

codecov bot commented Feb 24, 2023

Codecov Report

Merging #36943 (c8074a7) into trunk (f9f6e68) will increase coverage by 0.0%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             trunk   #36943   +/-   ##
========================================
  Coverage     46.7%    46.7%           
  Complexity   17178    17178           
========================================
  Files          429      429           
  Lines        64779    64779           
========================================
+ Hits         30240    30242    +2     
+ Misses       34539    34537    -2     
Impacted Files Coverage Δ
plugins/woocommerce/includes/class-wc-tax.php 79.0% <0.0%> (+0.5%) ⬆️

Copy link
Member

@barryhughes barryhughes left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

  • Changelog added.
  • Further testing instructions added.

@barryhughes barryhughes merged commit 7f5b65b into woocommerce:trunk Feb 24, 2023
@github-actions github-actions bot added this to the 7.6.0 milestone Feb 24, 2023
@helgatheviking helgatheviking deleted the issues/35004-attributes-saved-trigger branch February 24, 2023 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: Make "Used for variations" checkbox visible for other variable-ish product types.
2 participants