init_hooks(); } /** * Initialize hooks. * * @since 1.0.0 * @access private * @return void */ private function init_hooks() { // Single product page modifications. add_action( 'wp', array( $this, 'buddyx_surecart_single_page_setup' ) ); // Override sidebar settings for SureCart post types. add_filter( 'theme_mod_sidebar_option', array( $this, 'buddyx_surecart_override_sidebar_option' ) ); add_filter( 'theme_mod_single_post_sidebar_option', array( $this, 'buddyx_surecart_override_sidebar_option' ) ); // Page template assignment hooks - only fire when options change. add_action( 'update_option_surecart_shop_page_id', array( $this, 'buddyx_surecart_assign_page_template' ), 10, 2 ); add_action( 'update_option_surecart_checkout_page_id', array( $this, 'buddyx_surecart_assign_page_template' ), 10, 2 ); add_action( 'update_option_surecart_cart_page_id', array( $this, 'buddyx_surecart_assign_page_template' ), 10, 2 ); add_action( 'update_option_surecart_dashboard_page_id', array( $this, 'buddyx_surecart_assign_page_template' ), 10, 2 ); // Theme activation - run once. add_action( 'after_switch_theme', array( $this, 'buddyx_surecart_set_theme_defaults' ) ); // Customizer and cart setup - only if needed. if ( ! class_exists( 'WooCommerce' ) ) { add_action( 'init', array( $this, 'buddyx_surecart_add_customizer_option' ), 20 ); add_action( 'init', array( $this, 'buddyx_surecart_setup_cart_display' ), 5 ); } } /** * Setup modifications for SureCart single product pages. * * @since 1.0.0 * @access public * @return void */ public function buddyx_surecart_single_page_setup() { // Early return if not a SureCart single page. if ( ! is_singular( array( 'sc_product', 'sc_collection', 'sc_upsell' ) ) ) { return; } // Add inline CSS to hide duplicate elements. add_action( 'wp_head', array( $this, 'buddyx_surecart_add_single_page_styles' ), 999 ); // Remove all actions from buddyx_sub_header hook. $this->buddyx_surecart_remove_sub_header_actions(); // Prevent entry header from being loaded. add_filter( 'get_post_type', array( $this, 'buddyx_surecart_prevent_entry_header' ), 10, 2 ); } /** * Remove sub-header actions for SureCart pages. * * @since 1.0.0 * @access private * @return void */ private function buddyx_surecart_remove_sub_header_actions() { // Remove all actions hooked to buddyx_sub_header. remove_all_actions( 'buddyx_sub_header' ); } /** * Prevent entry header from showing on SureCart products. * * The theme shows entry-header for post type 'post', so we temporarily * change the post type to prevent this. * * @since 1.0.0 * @access public * @param string $post_type The post type. * @param int|null $post_id The post ID. * @return string Modified post type. */ public function buddyx_surecart_prevent_entry_header( $post_type, $post_id = null ) { // Only modify when checking for entry header template part. if ( doing_action( 'get_template_part_template-parts/content/entry-header' ) ) { return 'sc_product'; // Return actual type to prevent 'post' match. } return $post_type; } /** * Override sidebar option for SureCart post types. * * @since 1.0.0 * @access public * @param string $value Current sidebar option value. * @return string Modified sidebar option. */ public function buddyx_surecart_override_sidebar_option( $value ) { // Check if we're on a SureCart single page. if ( is_singular( array( 'sc_product', 'sc_collection', 'sc_upsell' ) ) ) { return 'none'; // This will trigger the no-sidebar layout. } return $value; } /** * Add CSS to hide duplicate elements on single pages. * * @since 1.0.0 * @access public * @return void */ public function buddyx_surecart_add_single_page_styles() { ?> 'site_header_enable_cart', 'label' => esc_html__( 'Enable Cart Icon?', 'buddyx' ), 'section' => 'site_header_primary_section', 'default' => '1', 'priority' => 10, 'choices' => array( 'on' => esc_html__( 'Yes', 'buddyx' ), 'off' => esc_html__( 'No', 'buddyx' ), ), 'tooltip' => esc_html__( 'Display SureCart cart icon in header', 'buddyx' ), 'transport' => 'refresh', ) ); } /** * Setup cart display functionality. * * @since 1.0.0 * @access public * @return void */ public function buddyx_surecart_setup_cart_display() { // Create compatibility functions. $this->buddyx_surecart_create_compatibility_functions(); // Add cart styles. add_action( 'wp_footer', array( $this, 'buddyx_surecart_add_cart_styles' ) ); } /** * Create compatibility functions for cart display. * * @since 1.0.0 * @access private * @return void */ private function buddyx_surecart_create_compatibility_functions() { // Create dummy is_woocommerce function if it doesn't exist. if ( ! function_exists( 'is_woocommerce' ) ) { /** * Dummy is_woocommerce function for compatibility. * * @since 1.0.0 * @return bool Always returns false. */ function is_woocommerce() { return false; } } // Override cart icon rendering function. if ( ! function_exists( 'buddyx_render_cart_icon' ) ) { /** * Render the SureCart cart icon in the header. * * @since 1.0.0 * @return void */ function buddyx_render_cart_icon() { // Check if cart is enabled. $cart_enabled = get_theme_mod( 'site_header_enable_cart', true ); if ( ! $cart_enabled ) { return; } ?>