JezK
Edit File: bottom-nav.php
<?php /** * Plugin Name: Mobile Bottom Navigation bottom of the page on mobile * Version: 1.1.0 * Author: Advaxe * License: GPL2 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Direct access block করল } /** * 1. Admin Settings Menu তৈরি করা */ add_action('admin_menu', 'organic_bottom_nav_create_menu'); function organic_bottom_nav_create_menu() { add_menu_page( 'Bottom Nav Settings', // Page Title 'Bottom Nav', // Menu Title 'manage_options', // Capability 'organic-bottom-nav-settings', // Menu Slug 'organic_bottom_nav_settings_page', // Callback Function 'dashicons-smartphone', // Icon 65 // Position ); } /** * 2. Settings অপশনগুলো রেজিস্টার করা */ add_action('admin_init', 'organic_bottom_nav_register_settings'); function organic_bottom_nav_register_settings() { $defaults = array( 'obn_bg_color' => '#fbf9f5', 'obn_text_color' => '#f48721', 'obn_icon_color' => '#000000', 'obn_home_bg' => '#f48721', 'obn_home_icon' => '#ffffff', 'obn_home_border' => '#ffffff', 'obn_cart_bg' => '#FFB800', 'obn_cart_text' => '#ffffff' ); foreach ( $defaults as $key => $value ) { register_setting( 'organic_bottom_nav_options_group', $key, array( 'default' => $value ) ); } } /** * 3. Admin Dashboard Settings Page HTML */ function organic_bottom_nav_settings_page() { ?> <div class="wrap"> <h1>Mobile Bottom Navigation Color Settings</h1> <p>এখান থেকে আপনার মোবাইল বটম নেভিগেশনের সমস্ত কালার পরিবর্তন করতে পারবেন।</p> <hr> <form method="post" action="options.php"> <?php settings_fields( 'organic_bottom_nav_options_group' ); ?> <?php do_settings_sections( 'organic_bottom_nav_options_group' ); ?> <table class="form-table" style="max-width: 600px;"> <!-- Nav Bar Background --> <tr> <th scope="row"><label for="obn_bg_color">Nav Bar Background</label></th> <td><input type="color" id="obn_bg_color" name="obn_bg_color" value="<?php echo esc_attr( get_option('obn_bg_color') ); ?>"></td> </tr> <!-- Nav Item Text Color --> <tr> <th scope="row"><label for="obn_text_color">Nav Item Text Color</label></th> <td><input type="color" id="obn_text_color" name="obn_text_color" value="<?php echo esc_attr( get_option('obn_text_color') ); ?>"></td> </tr> <!-- Nav Item Icon Color --> <tr> <th scope="row"><label for="obn_icon_color">Nav Item Icon Color</label></th> <td><input type="color" id="obn_icon_color" name="obn_icon_color" value="<?php echo esc_attr( get_option('obn_icon_color') ); ?>"></td> </tr> <!-- Center Home Button Background --> <tr> <th scope="row"><label for="obn_home_bg">Home Button Background</label></th> <td><input type="color" id="obn_home_bg" name="obn_home_bg" value="<?php echo esc_attr( get_option('obn_home_bg') ); ?>"></td> </tr> <!-- Center Home Button Icon Color --> <tr> <th scope="row"><label for="obn_home_icon">Home Icon Color</label></th> <td><input type="color" id="obn_home_icon" name="obn_home_icon" value="<?php echo esc_attr( get_option('obn_home_icon') ); ?>"></td> </tr> <!-- Center Home Button Border Color --> <tr> <th scope="row"><label for="obn_home_border">Home Button Border</label></th> <td><input type="color" id="obn_home_border" name="obn_home_border" value="<?php echo esc_attr( get_option('obn_home_border') ); ?>"></td> </tr> <!-- Cart Badge Background --> <tr> <th scope="row"><label for="obn_cart_bg">Cart Badge Background</label></th> <td><input type="color" id="obn_cart_bg" name="obn_cart_bg" value="<?php echo esc_attr( get_option('obn_cart_bg') ); ?>"></td> </tr> <!-- Cart Badge Text Color --> <tr> <th scope="row"><label for="obn_cart_text">Cart Badge Text Color</label></th> <td><input type="color" id="obn_cart_text" name="obn_cart_text" value="<?php echo esc_attr( get_option('obn_cart_text') ); ?>"></td> </tr> </table> <?php submit_button('Save Changes', 'primary', 'submit', true); ?> </form> </div> <?php } /** * 4. Front-end Output (Dynamic CSS সহ) */ add_action('wp_footer', 'custom_sticky_bottom_nav'); function custom_sticky_bottom_nav() { // ড্যাশবোর্ড থেকে কালার ডাটা রিসিভ করা হচ্ছে $bg_color = get_option('obn_bg_color', '#fbf9f5'); $text_color = get_option('obn_text_color', '#f48721'); $icon_color = get_option('obn_icon_color', '#000000'); // পূর্বের 000 ফিক্সড করা হয়েছে $home_bg = get_option('obn_home_bg', '#f48721'); $home_icon = get_option('obn_home_icon', '#ffffff'); $home_border = get_option('obn_home_border', '#ffffff'); $cart_bg = get_option('obn_cart_bg', '#FFB800'); $cart_text = get_option('obn_cart_text', '#ffffff'); // WooCommerce অ্যাক্টিভ আছে কিনা চেক করা (যাতে কোনো এরর না আসে) $cart_count = 0; $cart_url = '#'; $my_account_url = '#'; if ( class_exists('WooCommerce') ) { if ( WC()->cart ) { $cart_count = WC()->cart->get_cart_contents_count(); } $cart_url = wc_get_cart_url(); $my_account_url = get_permalink( get_option('woocommerce_myaccount_page_id') ); } ?> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"> <div class="organic-bottom-nav"> <a href="<?php echo site_url('/shop'); ?>" class="nav-item"> <i class="fa-solid fa-bag-shopping"></i> <span>Store</span> </a> <a href="<?php echo site_url('/contact'); ?>" class="nav-item"> <i class="fa-solid fa-headset"></i> <span>Contact</span> </a> <div class="nav-center-wrapper"> <a href="<?php echo site_url(); ?>" class="nav-center-btn"> <i class="fas fa-house"></i> <span>Home</span> </a> </div> <a href="<?php echo esc_url($cart_url); ?>" class="nav-item cart-icon-wrap"> <div class="cart-badge-container"> <i class="fas fa-shopping-cart"></i> <span class="cart-count"><?php echo esc_html($cart_count); ?></span> </div> <span>Cart</span> </a> <a href="<?php echo esc_url($my_account_url); ?>" class="nav-item"> <i class="fas fa-user"></i> <span><?php echo is_user_logged_in() ? 'Account' : 'Login'; ?></span> </a> </div> <style> /* CSS Styles */ .organic-bottom-nav { display: none; } @media only screen and (max-width: 768px) { body { padding-bottom: 70px; } .organic-bottom-nav { display: flex; justify-content: space-between; align-items: flex-end; position: fixed; bottom: 0; left: 0; width: 100%; background: <?php echo esc_attr($bg_color); ?>; box-shadow: 0 -2px 10px rgba(0,0,0,0.1); z-index: 9999; height: 60px; padding: 0 10px; box-sizing: border-box; border-top-left-radius: 1px; border-top-right-radius: 1px; } .nav-item { flex: 1; text-align: center; color: <?php echo esc_attr($text_color); ?>; text-text-decoration: none !important; font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; padding-bottom: 5px; } .nav-item i { font-size: 20px; margin-bottom: 4px; color: <?php echo esc_attr($icon_color); ?>; } .nav-item span { font-size: 11px; font-weight: 600; } /* Center Button Styling */ .nav-center-wrapper { flex: 1; position: relative; display: flex; justify-content: center; } .nav-center-btn { width: 60px; height: 60px; background: <?php echo esc_attr($home_bg); ?>; border-radius: 50%; position: absolute; bottom: 5px; display: flex; flex-direction: column; justify-content: center; align-items: center; color: <?php echo esc_attr($home_icon); ?> !important; text-decoration: none !important; box-shadow: 0 -3px 5px rgba(0,0,0,0.1); border: 2px solid <?php echo esc_attr($home_border); ?>; } .nav-center-btn i { font-size: 28px; margin-bottom: 6px; color: <?php echo esc_attr($home_icon); ?>; } .nav-center-btn span { font-size: 0px; font-weight: 600; } /* Cart Count Badge Styling */ .cart-badge-container { position: relative; display: inline-block; } span.cart-count { position: absolute; top: -6px; right: -10px; background: <?php echo esc_attr($cart_bg); ?>; color: <?php echo esc_attr($cart_text); ?>; font-size: 10px; width: 16px; height: 16px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; line-height: 1; } } </style> <?php } /** * 5. WooCommerce Live Cart Count Fragment */ add_filter( 'woocommerce_add_to_cart_fragments', 'refresh_bottom_nav_cart_count' ); function refresh_bottom_nav_cart_count( $fragments ) { if ( class_exists('WooCommerce') && WC()->cart ) { ob_start(); ?> <span class="cart-count"><?php echo WC()->cart->get_cart_contents_count(); ?></span> <?php $fragments['.cart-count'] = ob_get_clean(); } return $fragments; }