Skip to content

Restore rel key in loop add-to-cart filter arguments - #66856

Merged
kmanijak merged 2 commits into
trunkfrom
codex/fix-loop-add-to-cart-rel-compat
Jul 22, 2026
Merged

kmanijak merged 2 commits into
trunkfrom
codex/fix-loop-add-to-cart-rel-compat

Conversation

@kmanijak

@kmanijak kmanijak commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Submission Review Guidelines:

Changes proposed in this Pull Request:

In #66743 rel was conditionally removed from Product Button. But we should not change established shape of the public woocommerce_loop_add_to_cart_args filter arguments. This restores the rel key with an empty value for permalink anchors in the classic and Product Button PHP paths, while retaining nofollow for direct add-to-cart and external links.

Closes #66855.

Bug introduced in PR #66743.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Add a callback to woocommerce_loop_add_to_cart_args that appends sponsored to $args['attributes']['rel'] without first checking whether the key exists:
add_filter(
	'woocommerce_loop_add_to_cart_args',
	function ( $args ) {
		$args['attributes']['rel'] .= ' sponsored';
		return $args;
	}
);
  1. View a variable product in both a classic Shop archive and a Product Collection. Confirm there is no undefined-array-key warning and the rendered permalink button includes the appended sponsored relationship without nofollow.

Testing that has already taken place:

  • PHP syntax checks passed for all four changed PHP files.
  • Changed-file PHP lint passed.
  • Full committed branch PHP lint passed.
  • PHPStan completed with no errors for the two changed production files.
  • Targeted PHPUnit was not run locally because this worktree does not have its Composer and Node dependencies installed.

Milestone

Note: Check the box above to have the milestone automatically assigned when merged.
Alternatively (e.g. for point releases), manually assign the appropriate milestone.

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

Created manually.

Release Communication

Select if this PR needs a generated summary for release notes:

  • Feature Highlight - For user-facing features (what changed, user impact)
  • Developer Advisory - For developer-facing changes (what changed, how to detect, actions needed)
When to use each?

Feature Highlight: New features, UI changes, or improvements that merchants/store owners will notice.

  • Example: "New bulk editing for products", "Improved checkout performance"

Developer Advisory: Breaking changes, deprecations, or changes that affect themes/plugins/extensions.

  • Example: "Hook signature change", "Deprecated filter", "REST API field removed"

An AI will analyze your PR and post a draft comment for you to review and edit.

@github-actions github-actions Bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jul 22, 2026
@kmanijak
kmanijak marked this pull request as ready for review July 22, 2026 09:15
@kmanijak
kmanijak requested a review from Aljullu July 22, 2026 09:15
@woocommercebot
woocommercebot requested a review from a team July 22, 2026 09:15
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Testing Guidelines

Hi @Aljullu @woocommerce/woo-fse,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 4f7a48e8-d077-4c7d-9062-7eca55278ef6

📥 Commits

Reviewing files that changed from the base of the PR and between 39c2b59 and e375d62.

📒 Files selected for processing (5)
  • plugins/woocommerce/changelog/fix-loop-add-to-cart-rel-compat
  • plugins/woocommerce/includes/wc-template-functions.php
  • plugins/woocommerce/src/Blocks/BlockTypes/ProductButton.php
  • plugins/woocommerce/tests/php/includes/wc-template-functions-test.php
  • plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductButton.php

📝 Walkthrough

Walkthrough

WooCommerce loop and block product buttons now initialize permalink link rel attributes to an empty string. Existing nofollow overrides remain unchanged, and template and block tests verify rendered markup and filter arguments.

Changes

Loop add-to-cart rel compatibility

Layer / File(s) Summary
Default rel attribute rendering
plugins/woocommerce/includes/wc-template-functions.php, plugins/woocommerce/src/Blocks/BlockTypes/ProductButton.php
Loop and block product button links now include rel="" by default while preserving existing nofollow and external-product overrides.
Rel attribute coverage
plugins/woocommerce/tests/php/includes/wc-template-functions-test.php, plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductButton.php, plugins/woocommerce/changelog/*
Tests verify rendered links and filter arguments contain an empty rel attribute; the compatibility fix is recorded in the changelog.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: restoring the rel key in loop add-to-cart filter arguments.
Description check ✅ Passed The description is directly related to the code changes and explains the compatibility fix and its impact.
Linked Issues check ✅ Passed The changes restore the always-present rel key in both classic and Product Button paths, matching #66855.
Out of Scope Changes check ✅ Passed The only additional changelog fragment is directly related to the compatibility fix and is in scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-loop-add-to-cart-rel-compat

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a commit that changes plugin code.

@Aljullu Aljullu left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Heads-up that for testing I used this snippet:

add_filter(
	'woocommerce_loop_add_to_cart_args',
	function ( $args ) {
		if ( ! isset( $args['attributes']['type'] ) || 'button' !== $args['attributes']['type'] ) {
			$args['attributes']['rel'] .= ' sponsored';
		}
		return $args;
	}
);

Otherwise, I was still getting warnings in this branch and in trunk before #66743 was merged.

Besides that, it LGTM!

@kmanijak
kmanijak merged commit 8bfc108 into trunk Jul 22, 2026
91 of 97 checks passed
@kmanijak
kmanijak deleted the codex/fix-loop-add-to-cart-rel-compat branch July 22, 2026 12:46
@github-actions github-actions Bot added this to the 11.1.0 milestone Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

developer advisory plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

2 participants