esc_html__( 'Primary Menu', 'mega-mart' ), 'footer_menu' => esc_html__( 'Footer Menu', 'mega-mart' ), ) ); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', ) ); add_theme_support('custom-logo'); /* * WooCommerce Plugin Support */ add_theme_support( 'woocommerce' ); // Gutenberg wide images. add_theme_support( 'align-wide' ); /* * This theme styles the visual editor to resemble the theme style, * specifically font, colors, icons, and column width. */ add_editor_style( array( 'assets/css/editor-style.css', mega_mart_google_font() ) ); //Set up the WordPress core custom background feature. add_theme_support( 'custom-background', apply_filters( 'mega_mart_custom_background_args', array( 'default-color' => 'ffffff', 'default-image' => '', ) ) ); } endif; add_action( 'after_setup_theme', 'mega_mart_setup' ); /** * Set the content width in pixels, based on the theme's design and stylesheet. * * Priority 0 to make it available to lower priority callbacks. * * @global int $content_width */ function mega_mart_content_width() { $GLOBALS['content_width'] = apply_filters( 'mega_mart_content_width', 1170 ); } add_action( 'after_setup_theme', 'mega_mart_content_width', 0 ); /** * All Styles & Scripts. */ require_once get_template_directory() . '/inc/enqueue.php'; /** * Nav Walker fo Bootstrap Dropdown Menu. */ require_once get_template_directory() . '/inc/class-wp-bootstrap-navwalker.php'; /** * Implement the Custom Header feature. */ require_once get_template_directory() . '/inc/custom-header.php'; /** * Custom template tags for this theme. */ require_once get_template_directory() . '/inc/template-tags.php'; /** * Pagination for this theme. */ require_once get_template_directory() . '/inc/pagination/pagination.php'; /** * Dynamic Style */ require_once get_template_directory() . '/inc/dynamic_style.php'; /** * Custom functions that act independently of the theme templates. */ require_once get_template_directory() . '/inc/extras.php'; require_once get_template_directory() . '/inc/getting-start.php'; /** * Customizer additions. */ require_once get_template_directory() . '/inc/mega-mart-customizer.php'; require get_template_directory() . '/inc/customizer/customizer-repeater/functions.php'; /** * Frontpage */ require_once get_template_directory() . '/template-parts/sections/section-blog.php'; /* Data Migration From Lite Chilren to Lite Parent */ function mega_mart_child_theme_changes() { $changed_theme_slug = ''; $diff = []; if (wp_get_theme()->name == 'Mega Mart') { $parent_theme_mods = get_option('theme_mods_mega-mart'); if (!is_array($parent_theme_mods)) { $parent_theme_mods = []; } $parent_theme_mods = sanitize_theme_mod_values($parent_theme_mods); $themes = wp_get_themes(); foreach ($themes as $theme) { $template = $theme->get('Template'); if (!empty($template) && $template == 'mega-mart') { $child_slug = strtolower($theme->get('Name')); $hasSpace = preg_match('/\s/', $child_slug); if ($hasSpace) { $child_theme_slug = str_replace(' ', '-', $child_slug); } else { $child_theme_slug = $child_slug; } $child_theme_mods = get_option('theme_mods_' . $child_theme_slug); if (!is_array($child_theme_mods)) { $child_theme_mods = []; } $child_theme_mods = sanitize_theme_mod_values($child_theme_mods); // Compare individual theme mods $diff = array_diff_assoc($child_theme_mods, $parent_theme_mods); if (!empty($diff)) { $changed_theme_slug = $child_theme_slug; break; } } } if (!empty($changed_theme_slug)) { // Apply changes for the changed child theme $child_mods = get_option('theme_mods_' . $changed_theme_slug); if (is_array($child_mods)) { foreach ($child_mods as $child_mod_k => $child_mod_v) { if (is_array($child_mod_v) || is_object($child_mod_v)) { continue; } set_theme_mod($child_mod_k, $child_mod_v); } } } } } function sanitize_theme_mod_values($theme_mods) { $sanitized_mods = []; foreach ($theme_mods as $key => $value) { if (is_array($value) || is_object($value)) { $sanitized_mods[$key] = ''; } else { $sanitized_mods[$key] = $value; } } return $sanitized_mods; } add_action('after_switch_theme', 'mega_mart_child_theme_changes'); /* End Data Migration */ if( class_exists('woocommerce')): /* ========================================= Simple Product Custom Add To Cart Button ========================================*/ function custom_loop_add_to_cart_link( $button, $product ) { if ( $product && $product->is_type( 'simple' ) ) { $button = sprintf( '%s ', esc_url( $product->add_to_cart_url() ), esc_attr( isset( $quantity ) ? $quantity : 1 ), esc_attr( implode( ' ', array_filter( array( 'button', 'product_type_simple', 'add_to_cart_button', 'ajax_add_to_cart' ) ) ) ), wc_implode_html_attributes( array( 'data-product_id' => $product->get_id(), 'data-product_sku' => $product->get_sku(), 'aria-label' => $product->add_to_cart_description(), 'rel' => 'nofollow', ) ), esc_html( $product->add_to_cart_text() ) ); } return $button; } /* ============================================== Single Page Product Custom Add To Cart Button ============================================*/ add_action('wp', 'replace_single_product_add_to_cart'); function replace_single_product_add_to_cart() { if (is_product()) { global $post; $product = wc_get_product( $post->ID ); if ( $product && $product->is_type( 'simple' ) ) { remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); add_action('woocommerce_single_product_summary', 'custom_single_product_add_to_cart_button', 30); } } } function custom_single_product_add_to_cart_button() { global $product; if ($product->is_type('simple')) { $url = '?add-to-cart=' . $product->get_id(); echo ' Add To Cart '; } } /* ==================================================== Variation Product Form + Custom Add To Cart Button ==================================================*/ function custom_variable_add_to_cart_archive($button, $product) { if ($product->is_type('variable') ) { $available_variations = $product->get_available_variations(); $attributes = $product->get_variation_attributes(); ob_start(); echo '
'; echo ''; foreach ($attributes as $attribute_name => $options) { echo ''; echo ''; } echo '
'; wc_dropdown_variation_attribute_options(array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, )); echo '
'; echo '
'; echo ''; // Here’s your desired markup mimicked as a styled button echo ''; echo '
'; echo '
'; return ob_get_clean(); } return $button; } /* ========================================= Grouped or External Link Product Button ========================================*/ add_action( 'woocommerce_after_shop_loop_item', 'custom_replace_add_to_cart_button', 1 ); function custom_replace_add_to_cart_button() { global $product; // Remove default button remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); // Add custom button add_action( 'woocommerce_after_shop_loop_item', 'custom_add_button_output', 10 ); } function custom_add_button_output() { global $product; if ( $product->is_type( 'external' ) ) { echo 'Buy Now '; } elseif ( $product->is_type( 'grouped' ) ) { echo 'View Product '; } else { woocommerce_template_loop_add_to_cart(); // fallback for simple/variable } } /* ========================================= Remove Default Pagination From Shop Page ========================================*/ remove_action('woocommerce_after_shop_loop', 'woocommerce_pagination', 10); /* ================ Empty The cart ==============*/ add_action('init', 'custom_maybe_empty_cart'); function custom_maybe_empty_cart() { if (isset($_GET['empty-cart']) && $_GET['empty-cart'] == 'yes') { WC()->cart->empty_cart(); } } endif;