Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * DotSpice functions and definitions
- *
- * @link https://developer.wordpress.org/themes/basics/theme-functions/
- *
- * @package DotSpice
- * @version 1.1.0
- */
- if (!function_exists('dotspice_setup')) {
- /**
- * Sets up theme defaults and registers support for various WordPress features.
- *
- * Note that this function is hooked into the after_setup_theme hook, which
- * runs before the init hook. The init hook is too late for some features, such
- * as indicating support for post thumbnails.
- */
- function dotspice_setup()
- {
- // Add theme support for Translation
- load_theme_textdomain('dotspice', get_template_directory() . '/languages');
- // Add theme support for Automatic Feed Links
- add_theme_support('automatic-feed-links');
- // Add theme support for document Title tag
- add_theme_support('title-tag');
- // Add theme support for Featured Images
- add_theme_support('post-thumbnails');
- // Add theme support for HTML5 Semantic Markup
- add_theme_support('html5', array(
- 'search-form',
- 'comment-form',
- 'comment-list',
- 'gallery',
- 'caption',
- ));
- // Add theme support for Selective Refresh for widgets
- add_theme_support('customize-selective-refresh-widgets');
- // Add theme support for custom logo
- add_theme_support('custom-logo', array(
- 'height' => 250,
- 'width' => 250,
- 'flex-width' => true,
- 'flex-height' => true,
- ));
- // This theme uses wp_nav_menu() in one location.
- register_nav_menus(array(
- 'primary' => esc_html__('Primary', 'dotspice'),
- ));
- // Custom thumbnails sizes
- add_image_size('dotspice-blog-post', 1170, 545, true);
- // WP-SCSS Plugin folder Fix
- if (file_exists(WP_PLUGIN_DIR . '/wp-scss')) {
- if (!file_exists(WP_PLUGIN_DIR . '/wp-scss/cache')) {
- wp_mkdir_p(WP_PLUGIN_DIR . '/wp-scss/cache');
- // Flush rewrite rules Fix
- flush_rewrite_rules();
- }
- }
- }
- }
- add_action('after_setup_theme', 'dotspice_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 dotspice_content_width()
- {
- // This variable is intended to be overruled from themes.
- // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
- // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
- $GLOBALS['content_width'] = apply_filters('dotspice_content_width', $content_width);
- }
- add_action('after_setup_theme', 'dotspice_content_width', 0);
- /**
- * Include Sripts & Styles
- */
- function dotspice_scripts()
- {
- // Deregister scripts
- wp_deregister_script('jquery');
- wp_deregister_script('jquery-core');
- wp_deregister_script('jquery-migrate');
- // Register scripts
- wp_register_script('jquery-core', 'https://code.jquery.com/jquery-3.3.1.min.js', array(), null, false);
- wp_register_script('jquery', false, array('jquery-core'), null, false);
- // Enqueue scripts
- wp_enqueue_script('jquery');
- wp_enqueue_script('bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js', array('jquery'), '', true);
- wp_enqueue_script('aos-js', 'https://unpkg.com/aos@2.3.1/dist/aos.js', array('jquery'), '', true);
- wp_enqueue_script('owl-js', 'https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js?ver=5.4.2', array('jquery'), '', true);
- if (is_singular() && comments_open() && get_option('thread_comments')) {
- wp_enqueue_script('comment-reply');
- }
- wp_enqueue_script('script', get_template_directory_uri() . '/js/script.js', array(), filemtime(get_template_directory() . '/js/script.js'), true);
- // Dequeue styles
- wp_dequeue_style('wp-block-library');
- wp_dequeue_style('wc-block-style');
- wp_dequeue_style('cookie-consent-style');
- // Enqueue fonts
- if (get_theme_mod('google_fonts')) {
- wp_enqueue_style('google-fonts', esc_url(get_theme_mod('google_fonts')));
- }
- if (get_theme_mod('typekit_fonts')) {
- wp_enqueue_style('typekit-fonts', esc_url(get_theme_mod('typekit_fonts')));
- }
- // Enqueue styles
- wp_enqueue_style('bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css');
- wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css');
- wp_enqueue_style('aos-css', 'https://unpkg.com/aos@2.3.1/dist/aos.css');
- wp_enqueue_style('owl-css', 'https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css?ver=5.4.2');
- wp_enqueue_style('style', get_template_directory_uri() . '/css/style.css', array(), filemtime(get_template_directory() . '/css/style.css'));
- }
- add_action('wp_enqueue_scripts', 'dotspice_scripts');
- /**
- * Include Admin Sripts & Styles
- */
- function dotspice_admin_scripts()
- {
- // Enqueue scripts
- wp_enqueue_script('admin-script', get_template_directory_uri() . '/js/admin-script.js', array(), filemtime(get_template_directory() . '/js/admin-script.js'), true);
- // Enqueue styles
- wp_enqueue_style('admin-style', get_template_directory_uri() . '/css/admin-style.css', array(), filemtime(get_template_directory() . '/css/admin-style.css'));
- }
- add_action('admin_enqueue_scripts', 'dotspice_admin_scripts');
- /**
- * Register widget area.
- *
- * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
- */
- function dotspice_widgets_init()
- {
- $theme_sidebars = array(
- 'before-navbar' => array('tag' => 'h3', 'name' => 'Before Navbar'),
- 'jumbotron' => array('tag' => false, 'name' => 'Jumbotron'),
- 'archive-before-content' => array('tag' => 'h3', 'name' => 'Archive Before Content'),
- 'sidebar' => array('tag' => 'h3', 'name' => 'Sidebar'),
- 'footer' => array('tag' => false, 'name' => 'Footer'),
- );
- if (class_exists('woocommerce')) {
- $theme_sidebars = array_merge($theme_sidebars, array(
- 'shop-sidebar' => array('tag' => 'h3', 'name' => 'Shop Sidebar'),
- 'shop-before-content' => array('tag' => 'h3', 'name' => 'Shop Before Content'),
- 'shop-after-content' => array('tag' => 'h3', 'name' => 'Shop After Content'),
- ));
- }
- foreach ($theme_sidebars as $sidebar_ID => $sidebar_data) {
- register_sidebar(array(
- 'name' => sprintf(esc_html__('%s', 'dotspice'), $sidebar_data['name']),
- 'id' => $sidebar_ID,
- 'description' => esc_html__('Add widgets here.', 'dotspice'),
- 'before_widget' => ($sidebar_data['tag']) ? '<section id="%1$s" class="widget %2$s">' : '<section class="widget">',
- 'after_widget' => '</section>',
- 'before_title' => ($sidebar_data['tag']) ? '<' . $sidebar_data['tag'] . ' class="widget-title">' : '',
- 'after_title' => ($sidebar_data['tag']) ? '</' . $sidebar_data['tag'] . '>' : '',
- ));
- }
- }
- add_action('widgets_init', 'dotspice_widgets_init');
- /**
- * Enable shortcode on text widget
- */
- add_filter('widget_text', 'do_shortcode');
- /**
- * Require custom theme functions
- */
- require_once get_template_directory() . '/inc/template-functions.php'; // Functions which enhance the theme by hooking into WordPress
- require_once get_template_directory() . '/inc/customizer.php'; // Customizer additions
- require_once get_template_directory() . '/inc/titles.php'; // Custom titles
- require_once get_template_directory() . '/inc/jetpack.php'; // Jetpack compatibility file.
- require_once get_template_directory() . '/inc/woocommerce.php'; // WooCommerce settings
- require_once get_template_directory() . '/inc/shortcodes.php'; // Shortcodes
- require_once get_template_directory() . '/inc/menu.php'; // Nav menu search and Bootstrap menu style
- /**
- * Change Admin Title on Theme Editor Page
- */
- function change_page_title_on_theme_editor($admin_title, $title)
- {
- if (is_admin() && isset($_GET['file']) && $_GET['file'] != '') {
- $full_file_name = $_GET['file'];
- $file_name_array = explode('/', $full_file_name);
- if (count($file_name_array) > 1) {
- return array_pop($file_name_array) . ' | ' . $full_file_name;
- } else {
- return $full_file_name;
- }
- } else {
- return $admin_title;
- }
- }
- add_filter('admin_title', 'change_page_title_on_theme_editor', 10, 2);
- /**
- * Prr
- */
- function prr($data)
- {
- echo "<pre>";
- var_dump($data);
- echo "</pre>";
- }
- /**
- * Unique ID
- */
- function dotspice_unique_ID()
- {
- static $unique_ID = 0;
- return ++$unique_ID;
- }
- /**
- * Remove AUTOP from WPCF 7
- */
- add_filter('wpcf7_autop_or_not', '__return_false');
- /**
- * Theme layout
- */
- // Sidebar
- function dotspice_sidebar_col()
- {
- echo get_theme_mod('sidebar_col');
- }
- add_action('sidebar_col', 'dotspice_sidebar_col');
- // Content
- function dotspice_content_col()
- {
- echo get_theme_mod('content_col');
- }
- add_action('content_col', 'dotspice_content_col');
- // Blog Post
- function dotspice_blog_grid_col()
- {
- echo get_theme_mod('blog_grid_col');
- }
- add_action('blog_grid_col', 'dotspice_blog_grid_col');
- /**
- * Add Page Slug to Body Class
- */
- function dotspice_add_page_slug_body_class($classes)
- {
- global $post;
- if (isset($post)) {
- $classes[] = $post->post_type . '-' . $post->post_name;
- }
- return $classes;
- }
- add_filter('body_class', 'dotspice_add_page_slug_body_class');
- /**
- * Paste your code here
- */
- add_filter('woocommerce_product_tabs', 'woo_new_product_tab');
- function woo_new_product_tab($tabs)
- {
- // Adds the new tab
- $tabs['test_tab'] = array(
- 'title' => __('Parametry', 'woocommerce'),
- 'priority' => 10,
- 'callback' => 'woo_new_product_tab_content'
- );
- return $tabs;
- }
- function woo_new_product_tab_content()
- {
- if (!defined('ABSPATH')) {
- exit; // Exit if accessed directly.
- }
- global $post;
- $short_description = apply_filters('woocommerce_short_description', $post->post_excerpt);
- if (!$short_description) {
- return;
- }
- echo $short_description;
- }
- /**
- * Rename product data tabs
- */
- add_filter('woocommerce_product_tabs', 'woo_rename_tabs', 98);
- function woo_rename_tabs($tabs)
- {
- $tabs['additional_information']['title'] = __('Dostawa');
- return $tabs;
- }
- add_action('woocommerce_single_product_summary', 'single_product_price', 29);
- function single_product_price()
- {
- global $product;
- $price_single_product = $product->get_price();
- $one_piece = $price_single_product * get_field('ilosc_metrow_w_opakowaniu');
- if (get_field('ilosc_metrow_w_opakowaniu')) { ?>
- <div style="border: 2px solid #0f99e3; padding: 20px; margin-bottom: 30px;">
- <p><b>INFORMACJA CENOWA</b></p>
- <p style="font-size: 20px;" class="price"><?php echo $one_piece; ?> zł / opakowanie<br><small>(całe opakowanie zawiera: <?php echo get_field('ilosc_metrow_w_opakowaniu'); ?> m<sup>2</sup>)</small></p>
- <small>* Cena produktu jest ceną za paczkę, czyli cena pojedynczego m<sup>2</sup> pomnożoną przez ilość m<sup>2</sup> w opakowaniu</small>
- </div>
- <?php }
- }
- function cw_change_product_price_display($price)
- {
- global $product;
- $price_single_product = $product->get_price();
- $one_piece = $price_single_product * get_field('ilosc_metrow_w_opakowaniu');
- if (get_field('ilosc_metrow_w_opakowaniu') > 0) {
- $price .= ' / <small>m<sup>2</sup></small>';
- return $price;
- } else {
- return $price;
- }
- }
- add_filter('woocommerce_get_price_html', 'cw_change_product_price_display');
- add_action('woocommerce_before_calculate_totals', 'custom_cart_items_price');
- function custom_cart_items_price($cart)
- {
- if (is_admin() && !defined('DOING_AJAX'))
- return;
- if (did_action('woocommerce_before_calculate_totals') >= 2)
- return;
- foreach ($cart->get_cart() as $cart_item) {
- $product_id = $cart_item['data']->get_id();
- $quantity = get_post_meta($product_id, 'ilosc_metrow_w_opakowaniu', true);
- if ($quantity > 0) {
- $price = $cart_item['data']->get_price();
- $cart_item['data']->set_price(floatval($price * $quantity));
- } else {
- $price = $cart_item['data']->get_price();
- $cart_item['data']->set_price(floatval($price));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement