diff --git a/plugins/woocommerce-blocks/assets/js/settings/blocks/constants.js b/plugins/woocommerce-blocks/assets/js/settings/blocks/constants.js index 1c9a5b13ee5..90c385d1884 100644 --- a/plugins/woocommerce-blocks/assets/js/settings/blocks/constants.js +++ b/plugins/woocommerce-blocks/assets/js/settings/blocks/constants.js @@ -84,6 +84,7 @@ const defaultPage = { permalink: '', }; const storePages = getSetting( 'storePages', { + myaccount: defaultPage, shop: defaultPage, cart: defaultPage, checkout: defaultPage, @@ -109,4 +110,7 @@ export const CHECKOUT_ALLOWS_SIGNUP = getSetting( 'checkoutAllowsSignup', false ); -export const LOGIN_URL = getSetting( 'loginUrl', '/wp-login.php' ); + +export const LOGIN_URL = storePages.myaccount.permalink + ? storePages.myaccount.permalink + : getSetting( 'loginUrl', '/wp-login.php' ); diff --git a/plugins/woocommerce-blocks/src/Assets.php b/plugins/woocommerce-blocks/src/Assets.php index 4e3044bc700..c0a78c1d671 100644 --- a/plugins/woocommerce-blocks/src/Assets.php +++ b/plugins/woocommerce-blocks/src/Assets.php @@ -24,6 +24,7 @@ class Assets { add_action( 'body_class', array( __CLASS__, 'add_theme_body_class' ), 1 ); add_action( 'admin_body_class', array( __CLASS__, 'add_theme_admin_body_class' ), 1 ); add_filter( 'woocommerce_shared_settings', array( __CLASS__, 'get_wc_block_data' ) ); + add_action( 'woocommerce_login_form_end', array( __CLASS__, 'redirect_to_field' ) ); } /** @@ -141,11 +142,12 @@ class Assets { $tag_count = wp_count_terms( 'product_tag' ); $product_counts = wp_count_posts( 'product' ); $page_ids = [ - 'shop' => wc_get_page_id( 'shop' ), - 'cart' => wc_get_page_id( 'cart' ), - 'checkout' => wc_get_page_id( 'checkout' ), - 'privacy' => wc_privacy_policy_page_id(), - 'terms' => wc_terms_and_conditions_page_id(), + 'myaccount' => wc_get_page_id( 'myaccount' ), + 'shop' => wc_get_page_id( 'shop' ), + 'cart' => wc_get_page_id( 'cart' ), + 'checkout' => wc_get_page_id( 'checkout' ), + 'privacy' => wc_privacy_policy_page_id(), + 'terms' => wc_terms_and_conditions_page_id(), ]; $checkout = WC()->checkout(); @@ -186,11 +188,12 @@ class Assets { ], 'homeUrl' => esc_url( home_url( '/' ) ), 'storePages' => [ - 'shop' => self::format_page_resource( $page_ids['shop'] ), - 'cart' => self::format_page_resource( $page_ids['cart'] ), - 'checkout' => self::format_page_resource( $page_ids['checkout'] ), - 'privacy' => self::format_page_resource( $page_ids['privacy'] ), - 'terms' => self::format_page_resource( $page_ids['terms'] ), + 'myaccount' => self::format_page_resource( $page_ids['myaccount'] ), + 'shop' => self::format_page_resource( $page_ids['shop'] ), + 'cart' => self::format_page_resource( $page_ids['cart'] ), + 'checkout' => self::format_page_resource( $page_ids['checkout'] ), + 'privacy' => self::format_page_resource( $page_ids['privacy'] ), + 'terms' => self::format_page_resource( $page_ids['terms'] ), ], 'checkoutAllowsGuest' => $checkout instanceof \WC_Checkout && false === filter_var( $checkout->is_registration_required(), @@ -215,6 +218,17 @@ class Assets { ); } + /** + * Adds a redirect field to the login form so blocks can redirect users after login. + */ + public static function redirect_to_field() { + // phpcs:ignore WordPress.Security.NonceVerification + if ( empty( $_GET['redirect_to'] ) ) { + return; + } + echo ''; // phpcs:ignore WordPress.Security.NonceVerification + } + /** * Format a page object into a standard array of data. *