Files
WooCow/includes/class-woocow-pw-sync.php

52 lines
1.6 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* Adds an optional "sync password to mailboxes" checkbox on the
* WooCommerce My Account > Account Details page.
*
* Loaded automatically from woocow.php when WooCommerce is active.
*/
defined( 'ABSPATH' ) || exit;
class WooCow_PW_Sync {
public function __construct() {
// Render the checkbox below the password fields
add_action( 'woocommerce_edit_account_form', [ $this, 'render_checkbox' ] );
}
public function render_checkbox(): void {
// Only show if the current customer has mailcow assignments
global $wpdb;
$count = (int) $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM {$wpdb->prefix}woocow_assignments WHERE customer_id = %d",
get_current_user_id()
) );
if ( ! $count ) {
return;
}
?>
<fieldset class="woocow-pw-sync-field">
<legend><?php esc_html_e( 'Email Hosting', 'woocow' ); ?></legend>
<label for="woocow_sync_pw">
<input type="checkbox" name="woocow_sync_pw" id="woocow_sync_pw" value="1">
<?php esc_html_e( 'Also update password for all my email mailboxes (only applies when changing password above)', 'woocow' ); ?>
</label>
</fieldset>
<style>
.woocow-pw-sync-field {
border: 1px dashed #ddd;
border-radius: 6px;
padding: 12px 16px;
margin-top: 20px;
}
.woocow-pw-sync-field legend {
font-weight: 700;
padding: 0 6px;
color: #2271b1;
}
</style>
<?php
}
}