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

feat(modal-checkout): add filter for order button text #1650

Closed
wants to merge 3 commits into from

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Jan 23, 2024

All Submissions:

Changes proposed in this Pull Request:

Adds a filter to allow customizing the text for the button to complete an order in modal checkout.

How to test the changes in this Pull Request:

  1. Check out this branch.
  2. As a reader, start the following transactions via modal checkout (Donate block or Checkout Button block for non-donations):
  • One-time donation
  • Recurring donation
  • One-time non-donation purchase
  • Subscription non-donation purchase
  1. Confirm that the order button text displays as expected, unchanged from behavior in master (for any Newspack donation products: "Donate now", or whatever the default button label is for non-donation products).
  2. Add some custom code to your test site in a temporary plugin or in your theme's functions.php:
/**
 * Customize the order button text.
 *
 * @param string $text The order button text.
 * @param bool   $is_donation True if the current cart contains a Newspack donation product.
 * @param bool   $is_subscription True if the current cart contains a subscription product.
 * @return string The new text.
 */
function newspack_test_order_button_text( $text, $is_donation, $is_subscription ) {
	if ( $is_donation ) {
		$text = $is_subscription ? 'Custom text for recurring donations' : 'Custom text for one-time donations';
	} else {
		$text = $is_subscription ? 'Custom text for non-donation subscriptions' : 'Custom text for one-time non-donation purchases';
	}

	return $text;
}
\add_filter( 'newspack_blocks_modal_checkout_order_button_text', 'newspack_test_order_button_text', 10, 3 );
  1. Repeat step 2, and confirm that your custom text is shown as expected in each case.
Screenshot 2024-01-23 at 3 06 38 PM

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 ran tests with your changes locally?

@dkoo dkoo self-assigned this Jan 23, 2024
@dkoo dkoo requested a review from a team as a code owner January 23, 2024 22:07
Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

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

In the RAS-ACC project the logic for order button text has been decoupled so the Donation related text lives in the class-donations.php of newspack-plugin and the modal checkout related change lives in the class-modal-checkout.php of newspack-blocks. This will cause a conflict with the proposed filter when the project epic branch merges into master, since there's no longer donation related code in the modal checkout.

Although I don't mind the new filter, these can already be changed without additional code on our end by adding a filter the same way order_button_text works.

chickenn00dle and others added 3 commits January 24, 2024 11:58
This PR adds custom taxonomy exclusions to the Homepage Posts block, providing some more flexibility for the type of content that can be displayed (or not displayed) via the block.
BREAKING CHANGE: streamlined (Stripe) Donate block version is no more
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.6.15 to 9.6.16.
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/9.6.16/ChangeLog-9.6.md)
- [Commits](sebastianbergmann/phpunit@9.6.15...9.6.16)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
@dkoo dkoo force-pushed the feat/custom-order-button-text branch from f97c947 to cae5820 Compare January 24, 2024 19:00
@dkoo dkoo changed the base branch from master to epic/ras-acc January 24, 2024 19:00
@dkoo dkoo closed this Jan 24, 2024
@dkoo dkoo deleted the feat/custom-order-button-text branch January 24, 2024 19:01
@dkoo
Copy link
Contributor Author

dkoo commented Jan 24, 2024

@miguelpeixe thanks for highlighting. And true that the text can already be customized without a new filter, but I think a new filter could make the customization that much easier for non-engineers now, and also make it easier to implement a UI setting if we want to in the future. Will reopen this against the epic.

After looking a bit more closely at the decoupled code, I changed my mind—I don't think the new filter is needed after all. Thanks!

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

Successfully merging this pull request may close these issues.

3 participants