'; esc_html_e( 'The "AB Checkout Steps for WooCommerce" plugin requires WooCommerce to work. Please install and activate WooCommerce first.', 'ab-checkout-steps' ); echo '

'; } /* ========================================================= Settings ========================================================= */ /** * Get the configured number of checkout steps (3 or 4). Defaults to 3. */ function abchk_get_step_count() { $value = get_option( ABCHK_OPTION_STEP_COUNT, '3' ); $value = (int) $value; return ( 4 === $value ) ? 4 : 3; } /** * Get the ordered list of step labels based on the configured step count. */ function abchk_get_step_labels() { if ( 4 === abchk_get_step_count() ) { return array( __( 'Cart', 'ab-checkout-steps' ), __( 'Information', 'ab-checkout-steps' ), __( 'Shipping', 'ab-checkout-steps' ), __( 'Payment', 'ab-checkout-steps' ), ); } return array( __( 'Information', 'ab-checkout-steps' ), __( 'Shipping', 'ab-checkout-steps' ), __( 'Payment', 'ab-checkout-steps' ), ); } /** * Get the configured accent color (hex). Falls back to the default purple. */ function abchk_get_accent_color() { $value = get_option( ABCHK_OPTION_ACCENT_COLOR, ABCHK_DEFAULT_ACCENT_COLOR ); $value = sanitize_hex_color( $value ); return $value ? $value : ABCHK_DEFAULT_ACCENT_COLOR; } /** * Get the list of available progress bar styles: slug => label. */ function abchk_get_progress_styles() { return array( 'circles' => __( 'Circles — numbered circles connected by a line', 'ab-checkout-steps' ), 'chevron' => __( 'Chevron — connected arrow ribbon', 'ab-checkout-steps' ), 'minimal' => __( 'Minimal — plain text labels, no circles', 'ab-checkout-steps' ), 'bar' => __( 'Progress Bar — thick track with small dot markers', 'ab-checkout-steps' ), 'dots' => __( 'Dots — small compact dots, no numbers', 'ab-checkout-steps' ), 'boxes' => __( 'Boxes — solid numbered square blocks', 'ab-checkout-steps' ), ); } /** * Get the configured progress bar style slug. Defaults to "circles". */ function abchk_get_progress_style() { $value = get_option( ABCHK_OPTION_PROGRESS_STYLE, 'circles' ); $allowed = array_keys( abchk_get_progress_styles() ); return in_array( $value, $allowed, true ) ? $value : 'circles'; } function abchk_register_settings() { register_setting( 'abchk_settings_group', ABCHK_OPTION_STEP_COUNT, array( 'type' => 'string', 'sanitize_callback' => 'abchk_sanitize_step_count', 'default' => '3', ) ); register_setting( 'abchk_settings_group', ABCHK_OPTION_ACCENT_COLOR, array( 'type' => 'string', 'sanitize_callback' => 'abchk_sanitize_accent_color', 'default' => ABCHK_DEFAULT_ACCENT_COLOR, ) ); register_setting( 'abchk_settings_group', ABCHK_OPTION_PROGRESS_STYLE, array( 'type' => 'string', 'sanitize_callback' => 'abchk_sanitize_progress_style', 'default' => 'circles', ) ); } add_action( 'admin_init', 'abchk_register_settings' ); function abchk_sanitize_step_count( $value ) { return ( '4' === (string) $value ) ? '4' : '3'; } function abchk_sanitize_accent_color( $value ) { $color = sanitize_hex_color( $value ); return $color ? $color : ABCHK_DEFAULT_ACCENT_COLOR; } function abchk_sanitize_progress_style( $value ) { $allowed = array_keys( abchk_get_progress_styles() ); return in_array( $value, $allowed, true ) ? $value : 'circles'; } function abchk_add_settings_page() { add_options_page( __( 'AB Checkout Steps', 'ab-checkout-steps' ), __( 'AB Checkout Steps', 'ab-checkout-steps' ), 'manage_options', 'abchk-settings', 'abchk_render_settings_page' ); } add_action( 'admin_menu', 'abchk_add_settings_page' ); /** * Load the WordPress color picker only on this plugin's settings page. */ function abchk_admin_enqueue_settings_assets( $hook ) { if ( 'settings_page_abchk-settings' !== $hook ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_add_inline_script( 'wp-color-picker', "jQuery(function($){ $('.abchk-color-field').wpColorPicker(); });" ); } add_action( 'admin_enqueue_scripts', 'abchk_admin_enqueue_settings_assets' ); function abchk_render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $current_steps = abchk_get_step_count(); $current_color = abchk_get_accent_color(); $current_style = abchk_get_progress_style(); $styles = abchk_get_progress_styles(); ?>

' . esc_html__( 'Settings', 'ab-checkout-steps' ) . ''; array_unshift( $links, $settings_link ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'abchk_plugin_action_links' ); /* ========================================================= Frontend ========================================================= */ /** * Load CSS & JS only on the WooCommerce checkout page. */ function abchk_enqueue_checkout_assets() { if ( ! function_exists( 'is_checkout' ) || ! is_checkout() || is_wc_endpoint_url() ) { return; } wp_enqueue_style( 'abchk-checkout-style', ABCHK_PLUGIN_URL . 'assets/css/abchk-checkout.css', array(), ABCHK_PLUGIN_VERSION ); // Accent color is user-configurable, so it's injected as a CSS custom // property instead of being hardcoded in the stylesheet. $accent_color = abchk_get_accent_color(); wp_add_inline_style( 'abchk-checkout-style', ':root{--abchk-accent:' . esc_attr( $accent_color ) . ';}' ); wp_enqueue_script( 'abchk-checkout-script', ABCHK_PLUGIN_URL . 'assets/js/abchk-checkout.js', array( 'jquery' ), ABCHK_PLUGIN_VERSION, true ); wp_localize_script( 'abchk-checkout-script', 'abchkCheckout', array( 'stepCount' => abchk_get_step_count(), 'stepLabels' => abchk_get_step_labels(), 'nextLabel' => __( 'Next', 'ab-checkout-steps' ), 'backLabel' => __( 'Back', 'ab-checkout-steps' ), 'requiredMessage' => __( 'Please fill in all required fields before continuing.', 'ab-checkout-steps' ), ) ); } add_action( 'wp_enqueue_scripts', 'abchk_enqueue_checkout_assets' ); /** * Render the progress bar container above the checkout form. * The step content itself (billing, shipping, order review) is still * rendered normally by WooCommerce — grouping it into steps is handled * via JavaScript (see assets/js/abchk-checkout.js) so it stays compatible * with other themes/plugins that modify the checkout fields. */ function abchk_render_progress_bar() { if ( ! is_checkout() || is_wc_endpoint_url() ) { return; } $labels = abchk_get_step_labels(); $last_index = count( $labels ); ?> : one so the CSS/JS only run on checkout, * and one for the selected progress bar style (used to switch styling * in assets/css/abchk-checkout.css). */ function abchk_add_body_class( $classes ) { if ( function_exists( 'is_checkout' ) && is_checkout() && ! is_wc_endpoint_url() ) { $classes[] = 'abchk-multistep-active'; $classes[] = 'abchk-style-' . abchk_get_progress_style(); } return $classes; } add_filter( 'body_class', 'abchk_add_body_class' );