2024-05-02 17:51:32 +00:00
< ? php
2024-10-17 20:39:34 +00:00
if ( ! defined ( 'ABSPATH' ) ){
exit ; // Exit if accessed directly.
}
2024-05-02 17:51:32 +00:00
/**
* @ snippet WooCommerce Add Provision Info Tab
* @ author Ross Trottier
*/
2024-05-02 20:03:46 +00:00
2024-05-02 17:51:32 +00:00
// 1. Register new endpoint (URL) for My Account page
// Note: Re-save Permalinks or it will give 404 error
function federated_provision_info_endpoint () {
add_rewrite_endpoint ( 'provision-info' , EP_ROOT | EP_PAGES );
}
add_action ( 'init' , 'federated_provision_info_endpoint' );
// 2. Add new query var
function federated_provision_info_query_vars ( $vars ) {
$vars [] = 'provision-info' ;
return $vars ;
}
add_filter ( 'query_vars' , 'federated_provision_info_query_vars' , 0 );
// 3. Insert the new endpoint into the My Account menu
function federated_add_provision_info_link_my_account ( $items ) {
unset ( $items [ 'downloads' ]);
unset ( $items [ 'edit-address' ]);
return $items ;
}
add_filter ( 'woocommerce_account_menu_items' , 'federated_add_provision_info_link_my_account' );
// 4. Add content to the new tab
add_action ( 'woocommerce_account_content' , 'federated_provision_info_content' , 1 );
function federated_provision_info_content () {
global $wp ;
2024-05-02 21:51:56 +00:00
$home_url = home_url ();
$this_page_url = add_query_arg ( $wp -> query_vars , $home_url );
if ( $this_page_url != $home_url . '?page&pagename=my-account' ){
2024-05-02 17:51:32 +00:00
return ;
}
$user = wp_get_current_user ();
// Loop through user subscriptions
foreach ( wcs_get_users_subscriptions ( $user -> ID ) as $subscription ) {
if ( $subscription -> has_status ( 'active' )){
echo_subscription_info ( $subscription );
}
}
}
function echo_subscription_info ( $subscription ){
$subscription_id = $subscription -> ID ;
$domain = get_field ( 'domain' , $subscription_id );
$domain_status = get_field ( 'domain_status' , $subscription_id );
$provision_status = get_field ( 'provision_status' , $subscription_id );
$initial_admin_password = get_field ( 'initial_admin_password' , $subscription_id );
$tier = get_subscription_tier ( $subscription );
if ( ! empty ( $domain ) && $provision_status === 'provisioned' ){
echo '<div class="bg-white px-6 py-24 sm:py-32 lg:px-8">' ;
echo '<div class="mx-auto max-w-2xl text-center">' ;
2024-10-31 16:39:40 +00:00
echo '<h2 class="text-4xl font-bold tracking-tight text-gray-900 sm:text-6xl">Apps for: ' . $domain . '</h2>' ;
echo '<p class="mt-6 text-lg leading-8 text-gray-600"><a href="https://dashboard.' . $domain . '" target="_blank">Click here to access your apps.</a> Also, check out our helpful articles here for tips and tutorials on how to use these amazing open source tools.</p>' ;
2024-05-02 17:51:32 +00:00
if ( $domain_status === 'default' ){
echo '<p class="mt-6 text-lg leading-8 text-gray-600">This is a default domain, please do not change your admin password until you have switched to your custom domain.</p>' ;
}
echo '<p class="mt-6 text-lg leading-8 text-gray-600"><b>Admin Username:</b> admin@' . $domain . ' \\ <b>Initial Admin Password:</b> ' . $initial_admin_password . '</p>' ;
echo '</div>' ;
echo '</div>' ;
2024-10-31 16:39:40 +00:00
echo '<br />' ;
echo '<hr />' ;
echo '<br />' ;
2024-05-02 17:51:32 +00:00
} else if ( $provision_status === 'needs_provision' || $provision_status === 'provisioning' ) {
echo '<div class="bg-white px-6 py-24 sm:py-32 lg:px-8">' ;
echo '<div class="mx-auto max-w-2xl text-center">' ;
echo '<h2 class="text-4xl font-bold tracking-tight text-gray-900 sm:text-6xl">Welcome To Federated, Your Core is being provisioned as we speak.</h2>' ;
echo '<p class="mt-6 text-lg leading-8 text-gray-600">Your Federated Core is your very own, we provision each one made-to-order. Your apps, on your server, without having to share with anyone else. This only takes about 5 - 10 minutes, please check back shortly.</p>' ;
echo '</div>' ;
echo '</div>' ;
2024-10-31 16:39:40 +00:00
echo '<br />' ;
echo '<hr />' ;
echo '<br />' ;
2024-05-02 17:51:32 +00:00
}
}
add_action ( 'woocommerce_account_provision-info_endpoint' , 'federated_provision_info_content' );
// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format