From 2d181e255a622d67c82b050f18484c852528220d Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Mon, 2 Sep 2024 14:57:50 +0300 Subject: [PATCH 1/4] fix typo --- packages/js/src/redux/selectors/editorContext.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/redux/selectors/editorContext.js b/packages/js/src/redux/selectors/editorContext.js index 1beebcf37be..458265c93a6 100644 --- a/packages/js/src/redux/selectors/editorContext.js +++ b/packages/js/src/redux/selectors/editorContext.js @@ -27,7 +27,7 @@ export function getPostOrPageString( state ) { * * @param {Object} state The state. * - * @returns {string} Whether you're editing a produc. + * @returns {string} Whether you're editing a product. */ export function getIsProduct( state ) { return get( state, "editorContext.postTypeNameSingular" ) === "Product"; From 029b3fa4bc369ebbc86f56c717d5a9885fc17042 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Mon, 2 Sep 2024 15:04:05 +0300 Subject: [PATCH 2/4] refactor selector for isWooSeoUpsell --- packages/js/src/redux/selectors/isWooSEO.js | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/js/src/redux/selectors/isWooSEO.js b/packages/js/src/redux/selectors/isWooSEO.js index fe4d268ccdd..531e12ea98f 100644 --- a/packages/js/src/redux/selectors/isWooSEO.js +++ b/packages/js/src/redux/selectors/isWooSEO.js @@ -1,17 +1,10 @@ import { get } from "lodash"; - -/** - * Determines whether the WooCommerce SEO addon is not active in a product page. - * - * @returns {Boolean} Whether the plugin is WooCommerce SEO or not. - */ -export const getIsWooSeoUpsell = () => get( window, "wpseoScriptData.woocommerceUpsell", false ); - +import { getIsProduct } from "./editorContext"; /** * Determines whether the WooCommerce SEO addon is active. * - * @returns {Boolean} Whether the plugin is WooCommerce SEO or not. + * @returns {Boolean} Whether the plugin is WooCommerce SEO or not. */ export const getIsWooSeoActive = () => Boolean( get( window, "wpseoScriptData.isWooCommerceSeoActive", false ) ); @@ -21,3 +14,17 @@ export const getIsWooSeoActive = () => Boolean( get( window, "wpseoScriptData.is * @returns {boolean} True if WooCommerce is active. */ export const getIsWooCommerceActive = () => Boolean( get( window, "wpseoScriptData.isWooCommerceActive", false ) ); + +/** + * Determines whether the WooCommerce SEO addon is not active in a product page. + * + * @param {Object} state The state. + * @returns {Boolean} Whether the plugin is WooCommerce SEO or not. + */ +export const getIsWooSeoUpsell = ( state ) => { + const isWooSeoActive = getIsWooSeoActive(); + const isWooCommerceActive = getIsWooCommerceActive(); + const isProductPage = getIsProduct( state ); + + return ! isWooSeoActive && isWooCommerceActive && isProductPage; +}; From 19988a47f1213594d375a02526ee005174012816 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Mon, 2 Sep 2024 15:04:53 +0300 Subject: [PATCH 3/4] implement the selectors --- packages/js/src/components/SchemaTab.js | 2 +- packages/js/src/containers/SnippetEditor.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/js/src/components/SchemaTab.js b/packages/js/src/components/SchemaTab.js index 67d06a241bf..7b9c147e553 100644 --- a/packages/js/src/components/SchemaTab.js +++ b/packages/js/src/components/SchemaTab.js @@ -168,7 +168,7 @@ const Content = ( props ) => { const schemaPageTypeOptions = getSchemaTypeOptions( props.pageTypeOptions, props.defaultPageType, props.postTypeName ); const schemaArticleTypeOptions = getSchemaTypeOptions( props.articleTypeOptions, props.defaultArticleType, props.postTypeName ); const woocommerceUpsellLink = get( window, "wpseoScriptData.metabox.woocommerceUpsellSchemaLink", "" ); - const woocommerceUpsell = get( window, "wpseoScriptData.woocommerceUpsell", "" ); + const woocommerceUpsell = useSelect( ( select ) => select( STORE ).getIsWooSeoUpsell(), [] ); const [ focusedArticleType, setFocusedArticleType ] = useState( props.schemaArticleTypeSelected ); const woocommerceUpsellText = __( "Want your products stand out in search results with rich results like price, reviews and more?", "wordpress-seo" ); const isProduct = useSelect( ( select ) => select( STORE ).getIsProduct(), [] ); diff --git a/packages/js/src/containers/SnippetEditor.js b/packages/js/src/containers/SnippetEditor.js index 4a368a9aecc..b327974e141 100644 --- a/packages/js/src/containers/SnippetEditor.js +++ b/packages/js/src/containers/SnippetEditor.js @@ -1,5 +1,5 @@ import { compose } from "@wordpress/compose"; -import { withDispatch, withSelect } from "@wordpress/data"; +import { withDispatch, withSelect, useSelect } from "@wordpress/data"; import { __ } from "@wordpress/i18n"; import { SnippetEditor } from "@yoast/search-metadata-previews"; import { LocationConsumer } from "@yoast/externals/contexts"; @@ -51,7 +51,7 @@ export const mapEditorDataToPreview = function( data, context ) { */ const SnippetEditorWrapper = ( props ) => { const woocommerceUpsellLink = get( window, "wpseoScriptData.metabox.woocommerceUpsellGooglePreviewLink", "" ); - const woocommerceUpsell = get( window, "wpseoScriptData.woocommerceUpsell", "" ); + const woocommerceUpsell = useSelect( ( select ) => select( "yoast-seo/editor" ).getIsWooSeoUpsell(), [] ); const woocommerceUpsellText = __( "Want an enhanced Google preview of how your WooCommerce products look in the search results?", "wordpress-seo" ); return From 0035bda06910e3c433195a2c136ba392368039c6 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Mon, 2 Sep 2024 15:05:31 +0300 Subject: [PATCH 4/4] remove the `woocommerceUpsell` property from window object --- admin/metabox/class-metabox.php | 1 - 1 file changed, 1 deletion(-) diff --git a/admin/metabox/class-metabox.php b/admin/metabox/class-metabox.php index d734e0f78dd..1066a560ef6 100644 --- a/admin/metabox/class-metabox.php +++ b/admin/metabox/class-metabox.php @@ -901,7 +901,6 @@ public function enqueue() { 'isJetpackBoostNotPremium' => ( $is_block_editor ) ? YoastSEO()->classes->get( Jetpack_Boost_Not_Premium_Conditional::class )->is_met() : false, 'isWooCommerceSeoActive' => $woocommerce_seo_active, 'isWooCommerceActive' => $woocommerce_active, - 'woocommerceUpsell' => get_post_type( $post_id ) === 'product' && ! $woocommerce_seo_active && $woocommerce_active, ]; /**