Show forms on empty product pages

The current logic for form rendering assumes that a single product page
will trigger the filter `the_content`. This is not always true. In cases
where the product has no description, WooCommerce does not render the
description tab at all, which is where that filter usually fires (in my
testing).

This change ensures that we still give these forms a chance to render on
 such pages.

MAILPOET-5859
This commit is contained in:
John Oleksowicz
2024-02-07 14:52:29 -06:00
committed by Aschepikov
parent f6d8eb41b4
commit 0ab2be782d
3 changed files with 52 additions and 1 deletions

View File

@@ -130,7 +130,7 @@ class DisplayFormInWPContent {
* @return void
*/
public function maybeRenderFormsInFooter(): void {
if ($this->wp->isArchive() || $this->wp->isFrontPage() || $this->wp->isHome()) {
if ($this->wp->isArchive() || $this->wp->isFrontPage() || $this->wp->isHome() || $this->isWooProductPageWithoutContent()) {
$formMarkup = $this->getFormMarkup();
if (!empty($formMarkup)) {
$this->assetsController->setupFrontEndDependencies();
@@ -141,6 +141,20 @@ class DisplayFormInWPContent {
}
}
/**
* @return bool
*/
public function isWooProductPageWithoutContent(): bool {
if (
!$this->wp->isSingular('product')
|| !$this->wp->didAction('wp_footer')
) {
return false;
}
return !$this->wp->didFilter('the_content');
}
private function shouldDisplay(): bool {
$result = true;
// This is a fix Yoast plugin and Shapely theme compatibility