Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 115 additions & 1 deletion libresign-wp-customizations.php

@vitormattos vitormattos Jul 27, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best approach is to use the product note. It’s a default field for a product and it can support rich text. When we translate a product, the note also needs to be translated. Hardcoding the next steps would be a risky workaround.

Follow the suggested field to be used:

Image

If we add this PR as-is to the backlog, we can avoid approving a workaround that would generate a lot of code and extra work for a change that can be solved with a simple fix.

A more simple approach is to define a best place to display the product note.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more simple approach is to define a best place to display the product note.

I agree. It seems like the simplest way.

Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,13 @@ function libresign_get_account_help_url() {
return home_url( '/ajuda/' );
}

/**
* URL of the Nextcloud instance, shared with the WooCommerce integration plugin.
*/
function libresign_get_nextcloud_url() {
return trim( (string) get_option( 'nextcloud_api_host' ) );
}

/**
* Render a CTA on every customer account screen that points to the Nextcloud instance.
*/
Expand All @@ -613,7 +620,7 @@ function libresign_render_nextcloud_account_button() {
return;
}

$nextcloud_host = trim( (string) get_option( 'nextcloud_api_host' ) );
$nextcloud_host = libresign_get_nextcloud_url();

if ( '' === $nextcloud_host ) {
return;
Expand All @@ -631,6 +638,113 @@ function libresign_render_nextcloud_account_button() {
}
add_action( 'woocommerce_before_account_navigation', 'libresign_render_nextcloud_account_button', 20 );

/**
* Store and read the WooCommerce Subscriptions thank you message, so it can be moved
* into the next steps block instead of being printed on its own.
*
* @param string|null $message Message to store. Omit to read the stored one.
*/
function libresign_thank_you_subscription_message( $message = null ) {
static $stored = '';

if ( null !== $message ) {
$stored = (string) $message;
}

return $stored;
}

add_filter( 'woocommerce_subscriptions_thank_you_message', function ( $message ) {
libresign_thank_you_subscription_message( $message );

return '';
}, 99 );

/**
* Print the subscription notice with the same allowlist the Subscriptions plugin applies to it.
*/
function libresign_print_thank_you_subscription_message( $message ) {
if ( '' === $message ) {
return;
}

echo wp_kses(
$message,
array(
'a' => array(
'href' => array(),
'title' => array(),
),
'p' => array(),
'em' => array(),
'strong' => array(),
)
);
}

/**
* Render the next steps on the order received page: the subscription status notice,
* plus links to the account dashboard (WordPress) and to the first signature (Nextcloud).
*
* @param int $order_id Order being displayed.
*/
function libresign_render_thank_you_next_steps( $order_id = 0 ) {
$subscription_message = libresign_thank_you_subscription_message();
$order = $order_id ? wc_get_order( $order_id ) : false;
$account_url = '';
$nextcloud_url = '';

libresign_thank_you_subscription_message( '' );

if ( $order && is_user_logged_in() && $order->get_user_id() === get_current_user_id() ) {
$account_url = (string) wc_get_page_permalink( 'myaccount' );

if ( $order->is_paid() ) {
$nextcloud_url = libresign_get_nextcloud_url();
}
}

if ( '' === $account_url && '' === $nextcloud_url ) {
libresign_print_thank_you_subscription_message( $subscription_message );

return;
}

echo '<div class="libresign-thankyou-next-steps" style="margin-top: 1.5rem; padding: 1rem; border: 1px solid currentColor; border-radius: 0.75rem;">';

printf(
'<p style="margin: 0 0 1rem 0;">%s</p>',
esc_html__( 'What would you like to do next?', 'libresign-wp-customizations' )
);

if ( '' !== $subscription_message ) {
echo '<div class="libresign-thankyou-next-steps__notice" style="margin: 0 0 1rem 0;">';
libresign_print_thank_you_subscription_message( $subscription_message );
echo '</div>';
}

echo '<p style="margin: 0; display: flex; flex-wrap: wrap; gap: 0.75rem;">';

if ( '' !== $account_url ) {
printf(
'<a class="wp-block-button__link wp-element-button is-style-outline" href="%s">%s</a>',
esc_url( $account_url ),
esc_html__( 'Go to your dashboard', 'libresign-wp-customizations' )
);
}

if ( '' !== $nextcloud_url ) {
printf(
'<a class="wp-block-button__link wp-element-button" href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
esc_url( $nextcloud_url ),
esc_html__( 'Sign your first document', 'libresign-wp-customizations' )
);
}

echo '</p></div>';
}
add_action( 'woocommerce_thankyou', 'libresign_render_thank_you_next_steps', 11 );

/**
* Confirmation strings for each subscription status change that requires an extra step.
*/
Expand Down