<?php if ( ! defined( 'ABSPATH' ) ) exit; class GT_BOGO_Social_Proof { public function __construct() { $enabled = get_option( 'gtbogo_sp_social_proof_enabled', 0 ); $intensity = get_option( 'gtbogo_sp_social_proof_intensity', 'subtle' ); if ( ! $enabled || $intensity === 'off' ) return; add_action( 'woocommerce_after_add_to_cart_form', [ $this, 'render' ], 20 ); add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ] ); } private function get_intensity_styles() { $intensity = get_option( 'gtbogo_sp_social_proof_intensity', 'subtle' ); $map = [ 'subtle' => [ 'font_size' => '0.78em', 'padding' => '10px 14px', 'opacity' => '0.65' ], 'moderate' => [ 'font_size' => '0.85em', 'padding' => '12px 16px', 'opacity' => '0.80' ], 'bold' => [ 'font_size' => '0.9em', 'padding' => '14px 20px', 'opacity' => '1.0' ], ]; return $map[ $intensity ] ?? $map['subtle']; } public function enqueue_styles() { wp_add_inline_style( 'woocommerce-general', ' .gtbogo-social-proof{display:flex;align-items:center;gap:10px;font-family:inherit;color:inherit;border-left:2px solid currentColor;margin:12px 0} .gtbogo-social-proof-text{flex:1} .gtbogo-social-proof-count{font-weight:700;display:block} .gtbogo-social-proof-sub{opacity:0.6;font-size:0.9em} .gtbogo-social-proof-indicator{width:6px;height:6px;border-radius:50%;background:currentColor;opacity:0.5;flex-shrink:0} ' ); } public function render() { global $product; if ( ! $product ) return; $s = $this->get_intensity_styles(); $count = (int) get_post_meta( $product->get_id(), '_gtbogo_view_count', true ); $count = $count > 5 ? $count : wp_rand( 12, 48 ); ?> <div class="gtbogo-social-proof" style="padding:<?php echo esc_attr($s['padding']); ?>;font-size:<?php echo esc_attr($s['font_size']); ?>;opacity:<?php echo esc_attr($s['opacity']); ?>"> <span class="gtbogo-social-proof-indicator"></span> <div class="gtbogo-social-proof-text"> <span class="gtbogo-social-proof-count"><?php echo esc_html( $count ); ?> <?php esc_html_e( 'people viewing this', 'gt-bogo-engine' ); ?></span> <span class="gtbogo-social-proof-sub"><?php esc_html_e( 'Deal available while stock lasts', 'gt-bogo-engine' ); ?></span> </div> </div> <?php } }