JezK
Edit File: premium-order-buttons.php
<?php /** * Plugin Name: Premium Order Buttons * Description: Adds premium Call, WhatsApp, and Messenger order buttons after the WooCommerce cart button. * Version: 1.0 * Author: Your Name */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } // 1. Add Admin Menu add_action('admin_menu', 'pob_add_admin_menu'); function pob_add_admin_menu() { add_menu_page( 'Order Buttons', 'Order Buttons', 'manage_options', 'premium-order-buttons', 'pob_admin_page_html', 'dashicons-smartphone', 56 ); } // 2. Admin Page HTML & Logic function pob_admin_page_html() { // Save Settings if (isset($_POST['pob_save_settings']) && check_admin_referer('pob_save_action', 'pob_nonce')) { $options = [ 'btn_height' => sanitize_text_field($_POST['btn_height']), 'font_size' => sanitize_text_field($_POST['font_size']), 'call_status' => isset($_POST['call_status']) ? 'on' : 'off', 'call_text' => sanitize_text_field($_POST['call_text']), 'call_number' => sanitize_text_field($_POST['call_number']), 'wa_status' => isset($_POST['wa_status']) ? 'on' : 'off', 'wa_text' => sanitize_text_field($_POST['wa_text']), 'wa_number' => sanitize_text_field($_POST['wa_number']), 'msg_status' => isset($_POST['msg_status']) ? 'on' : 'off', 'msg_text' => sanitize_text_field($_POST['msg_text']), 'msg_link' => sanitize_url($_POST['msg_link']), ]; update_option('pob_settings', $options); echo '<div class="updated"><p>Settings Saved Successfully!</p></div>'; } // Get Current Settings $defaults = [ 'btn_height' => '50', 'font_size' => '16', 'call_status' => 'on', 'call_text' => 'অর্ডার করতে কল করুন', 'call_number' => '+8801XXXXXXXXX', 'wa_status' => 'on', 'wa_text' => 'হোয়াটস্যাপে অর্ডার করুন', 'wa_number' => '8801XXXXXXXXX', 'msg_status' => 'on', 'msg_text' => 'ফেইসবুকে অর্ডার করুন', 'msg_link' => 'https://m.me/yourpage' ]; $opt = wp_parse_args(get_option('pob_settings', []), $defaults); ?> <div class="wrap"> <h2>Premium Order Buttons - Settings</h2> <form method="post" action="" style="background:#fff; padding:20px; border-radius:8px; box-shadow:0 1px 3px rgba(0,0,0,0.1); max-width:800px;"> <?php wp_nonce_field('pob_save_action', 'pob_nonce'); ?> <table class="form-table"> <tr><th colspan="2" style="background:#f1f1f1; padding:10px;"><b>Global Styling (ডিজাইন সেটিংস)</b></th></tr> <tr> <th>Button Height (px)</th> <td><input type="number" name="btn_height" value="<?php echo esc_attr($opt['btn_height']); ?>" style="width:100px;"> px</td> </tr> <tr> <th>Font Size (px)</th> <td><input type="number" name="font_size" value="<?php echo esc_attr($opt['font_size']); ?>" style="width:100px;"> px</td> </tr> <tr><th colspan="2" style="background:#f1f1f1; padding:10px; margin-top:20px; display:block;"><b>Call Button (কল বাটন)</b></th></tr> <tr> <th>Enable Call Button</th> <td><input type="checkbox" name="call_status" <?php checked($opt['call_status'], 'on'); ?>></td> </tr> <tr> <th>Button Text</th> <td><input type="text" name="call_text" value="<?php echo esc_attr($opt['call_text']); ?>" class="regular-text"></td> </tr> <tr> <th>Phone Number</th> <td><input type="text" name="call_number" value="<?php echo esc_attr($opt['call_number']); ?>" class="regular-text"></td> </tr> <tr><th colspan="2" style="background:#f1f1f1; padding:10px; margin-top:20px; display:block;"><b>WhatsApp Button (হোয়াটসঅ্যাপ বাটন)</b></th></tr> <tr> <th>Enable WhatsApp</th> <td><input type="checkbox" name="wa_status" <?php checked($opt['wa_status'], 'on'); ?>></td> </tr> <tr> <th>Button Text</th> <td><input type="text" name="wa_text" value="<?php echo esc_attr($opt['wa_text']); ?>" class="regular-text"></td> </tr> <tr> <th>WhatsApp Number<br><small>(Country code without +)</small></th> <td><input type="text" name="wa_number" value="<?php echo esc_attr($opt['wa_number']); ?>" class="regular-text"></td> </tr> <tr><th colspan="2" style="background:#f1f1f1; padding:10px; margin-top:20px; display:block;"><b>Messenger Button (মেসেঞ্জার বাটন)</b></th></tr> <tr> <th>Enable Messenger</th> <td><input type="checkbox" name="msg_status" <?php checked($opt['msg_status'], 'on'); ?>></td> </tr> <tr> <th>Button Text</th> <td><input type="text" name="msg_text" value="<?php echo esc_attr($opt['msg_text']); ?>" class="regular-text"></td> </tr> <tr> <th>Messenger Link<br><small>(e.g. https://m.me/page)</small></th> <td><input type="text" name="msg_link" value="<?php echo esc_attr($opt['msg_link']); ?>" class="regular-text"></td> </tr> </table> <p class="submit"> <input type="submit" name="pob_save_settings" class="button-primary" value="Save All Changes"> </p> </form> </div> <?php } // 3. Frontend Display (After Add to Cart) add_action('woocommerce_after_add_to_cart_form', 'pob_display_frontend_buttons'); function pob_display_frontend_buttons() { $defaults = [ 'btn_height' => '50', 'font_size' => '16', 'call_status' => 'on', 'call_text' => 'অর্ডার করতে কল করুন', 'call_number' => '', 'wa_status' => 'on', 'wa_text' => 'হোয়াটস্যাপে অর্ডার করুন', 'wa_number' => '', 'msg_status' => 'on', 'msg_text' => 'ফেইসবুকে অর্ডার করুন', 'msg_link' => '' ]; $opt = wp_parse_args(get_option('pob_settings', []), $defaults); // CSS Output ?> <style> .pob-container { margin-top: 15px; display: flex; flex-direction: column; gap: 10px; width: 100%; } .pob-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; text-decoration: none !important; color: #fff !important; font-weight: 600; border-radius: 8px; box-sizing: border-box; transition: all 0.3s ease; box-shadow: 0 4px 6px rgba(0,0,0,0.1); height: <?php echo esc_attr($opt['btn_height']); ?>px; font-size: <?php echo esc_attr($opt['font_size']); ?>px; } .pob-btn svg { width: 24px; height: 24px; fill: currentColor; } .pob-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0,0,0,0.15); color: #fff !important; } /* Premium Colors */ .pob-call { background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%); } .pob-wa { background: linear-gradient(135deg, #25D366 0%, #128C7E 100%); } .pob-msg { background: linear-gradient(135deg, #00C6FF 0%, #0072FF 100%); } </style> <div class="pob-container"> <?php if ($opt['call_status'] === 'on') : ?> <a href="tel:<?php echo esc_attr($opt['call_number']); ?>" class="pob-btn pob-call"> <svg viewBox="0 0 24 24"><path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56a.977.977 0 00-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"/></svg> <?php echo esc_html($opt['call_text']); ?> </a> <?php endif; ?> <?php if ($opt['wa_status'] === 'on') : ?> <a href="https://wa.me/<?php echo esc_attr($opt['wa_number']); ?>" target="_blank" class="pob-btn pob-wa"> <svg viewBox="0 0 24 24"><path d="M12.031 6.172c-3.181 0-5.767 2.586-5.768 5.766-.001 1.298.38 2.27 1.019 3.287l-.582 2.128 2.182-.573c.978.58 1.711.928 3.145.929 3.178 0 5.767-2.587 5.768-5.766.001-3.187-2.575-5.77-5.764-5.771zm3.392 8.244c-.144.405-.837.774-1.17.824-.299.045-.677.063-1.092-.125-.397-.18-1.22-.453-2.327-1.446-1.458-1.314-2.008-2.945-2.063-3.002-.056-.058-.492-.656-.492-1.58 0-.923.473-1.378.64-1.564.167-.185.356-.217.476-.217.119 0 .237.001.343.006.11.004.258-.041.405.311.151.36.516 1.259.563 1.353.048.094.079.204.016.327-.064.125-.095.204-.191.316-.095.111-.2.245-.285.334-.095.101-.194.21-.082.404.111.194.495.823 1.059 1.325.727.646 1.328.847 1.52.941.191.094.303.079.418-.052.115-.131.498-.58.633-.781.135-.201.269-.168.444-.102.175.066 1.111.525 1.302.621.191.096.318.144.366.223.048.079.048.455-.096.86zM11.994 2C6.471 2 2 6.471 2 11.994c0 1.944.558 3.753 1.516 5.289l-1.516 4.717 4.887-1.487C8.361 21.497 10.117 22 11.994 22 17.517 22 22 17.517 22 11.994 22 6.471 17.517 2 11.994 2z"/></svg> <?php echo esc_html($opt['wa_text']); ?> </a> <?php endif; ?> <?php if ($opt['msg_status'] === 'on') : ?> <a href="<?php echo esc_url($opt['msg_link']); ?>" target="_blank" class="pob-btn pob-msg"> <svg viewBox="0 0 24 24"><path d="M12 2C6.36 2 1.8 6.13 1.8 11.23c0 2.91 1.51 5.49 3.86 7.16v3.42l3.52-1.94c.9.25 1.85.38 2.82.38 5.64 0 10.2-4.13 10.2-9.23S17.64 2 12 2zm1.09 12.3l-2.79-2.98-5.44 2.98 5.96-6.33 2.89 2.98 5.34-2.98-5.96 6.33z"/></svg> <?php echo esc_html($opt['msg_text']); ?> </a> <?php endif; ?> </div> <?php }