@@ -46,6 +46,7 @@ public static function init() {
4646 \add_action ( 'newspack_woocommerce_after_account_addresses ' , [ __CLASS__ , 'delete_address_modals ' ] );
4747 \add_action ( 'woocommerce_after_save_address_validation ' , [ __CLASS__ , 'handle_delete_address_submission ' ], 10 , 4 );
4848 \add_filter ( 'woocommerce_address_to_edit ' , [ __CLASS__ , 'reorder_address_fields ' ], PHP_INT_MAX , 2 );
49+ \add_action ( 'woocommerce_account_content ' , [ __CLASS__ , 'render_content_around_shortcode ' ], 0 );
4950 }
5051
5152 /**
@@ -870,5 +871,47 @@ public static function reorder_address_fields( $address, $load_address ) {
870871
871872 return $ address ;
872873 }
874+
875+ /**
876+ * Render the content around the [woocommerce_my_account] shortcode inside the
877+ * woocommerce-MyAccount-content context.
878+ *
879+ * This is necessary because of the highly customized grid layout.
880+ */
881+ public static function render_content_around_shortcode () {
882+ // Only allow custom content under the dashboard (root) or edit-account (default redirect) pages.
883+ global $ wp ;
884+ if ( ! isset ( $ wp ->query_vars ['page ' ] ) && ! empty ( $ wp ->query_vars ) && ! isset ( $ wp ->query_vars ['edit-account ' ] ) ) {
885+ return ;
886+ }
887+
888+ $ content = get_the_content ();
889+ if ( empty ( $ content ) ) {
890+ return ;
891+ }
892+ $ parts = explode ( '[woocommerce_my_account] ' , $ content );
893+
894+ $ before = ! empty ( $ parts [0 ] ) ? $ parts [0 ] : '' ;
895+ if ( ! empty ( $ before ) ) {
896+ add_action (
897+ 'woocommerce_account_content ' ,
898+ function () use ( $ before ) {
899+ echo apply_filters ( 'the_content ' , $ before ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
900+ },
901+ 9 // Right before the shortcode.
902+ );
903+ }
904+
905+ $ after = ! empty ( $ parts [1 ] ) ? $ parts [1 ] : '' ;
906+ if ( ! empty ( $ after ) ) {
907+ add_action (
908+ 'woocommerce_account_content ' ,
909+ function () use ( $ after ) {
910+ echo apply_filters ( 'the_content ' , $ after ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
911+ },
912+ 11 // Right after the shortcode.
913+ );
914+ }
915+ }
873916}
874917My_Account_UI_V1::init ();
0 commit comments