Skip to content

Commit

Permalink
Merge pull request #21589 from Yoast/21588-remove-woocommerceupsell-f…
Browse files Browse the repository at this point in the history
…rom-wpseoscriptdata

21588 remove woocommerceupsell from wpseoscriptdata
  • Loading branch information
pls78 authored Sep 3, 2024
2 parents 674f65d + 2e5f682 commit 7c62a90
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
1 change: 0 additions & 1 deletion admin/metabox/class-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/components/SchemaTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(), [] );
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/containers/SnippetEditor.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 <LocationConsumer>
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/redux/selectors/editorContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
25 changes: 16 additions & 9 deletions packages/js/src/redux/selectors/isWooSEO.js
Original file line number Diff line number Diff line change
@@ -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 ) );

Expand All @@ -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;
};

0 comments on commit 7c62a90

Please sign in to comment.