Advertisement
Socialking

Untitled

Mar 28th, 2022
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.63 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * DotSpice functions and definitions
  5.  *
  6.  * @link https://developer.wordpress.org/themes/basics/theme-functions/
  7.  *
  8.  * @package DotSpice
  9.  * @version 1.1.0
  10.  */
  11.  
  12.  
  13. if (!function_exists('dotspice_setup')) {
  14.  
  15.       /**
  16.        * Sets up theme defaults and registers support for various WordPress features.
  17.        *
  18.        * Note that this function is hooked into the after_setup_theme hook, which
  19.        * runs before the init hook. The init hook is too late for some features, such
  20.        * as indicating support for post thumbnails.
  21.        */
  22.       function dotspice_setup()
  23.       {
  24.  
  25.             // Add theme support for Translation
  26.             load_theme_textdomain('dotspice', get_template_directory() . '/languages');
  27.  
  28.             // Add theme support for Automatic Feed Links
  29.             add_theme_support('automatic-feed-links');
  30.  
  31.             // Add theme support for document Title tag
  32.             add_theme_support('title-tag');
  33.  
  34.             // Add theme support for Featured Images
  35.             add_theme_support('post-thumbnails');
  36.  
  37.             // Add theme support for HTML5 Semantic Markup
  38.             add_theme_support('html5', array(
  39.                   'search-form',
  40.                   'comment-form',
  41.                   'comment-list',
  42.                   'gallery',
  43.                   'caption',
  44.             ));
  45.  
  46.             // Add theme support for Selective Refresh for widgets
  47.             add_theme_support('customize-selective-refresh-widgets');
  48.  
  49.             // Add theme support for custom logo
  50.             add_theme_support('custom-logo', array(
  51.                   'height'      => 250,
  52.                   'width'       => 250,
  53.                   'flex-width'  => true,
  54.                   'flex-height' => true,
  55.             ));
  56.  
  57.             // This theme uses wp_nav_menu() in one location.
  58.             register_nav_menus(array(
  59.                   'primary' => esc_html__('Primary', 'dotspice'),
  60.             ));
  61.  
  62.             // Custom thumbnails sizes
  63.             add_image_size('dotspice-blog-post', 1170, 545, true);
  64.  
  65.             // WP-SCSS Plugin folder Fix
  66.             if (file_exists(WP_PLUGIN_DIR . '/wp-scss')) {
  67.                   if (!file_exists(WP_PLUGIN_DIR . '/wp-scss/cache')) {
  68.                         wp_mkdir_p(WP_PLUGIN_DIR . '/wp-scss/cache');
  69.  
  70.                         // Flush rewrite rules Fix
  71.                         flush_rewrite_rules();
  72.                   }
  73.             }
  74.       }
  75. }
  76. add_action('after_setup_theme', 'dotspice_setup');
  77.  
  78.  
  79. /**
  80.  * Set the content width in pixels, based on the theme's design and stylesheet.
  81.  *
  82.  * Priority 0 to make it available to lower priority callbacks.
  83.  *
  84.  * @global int $content_width
  85.  */
  86. function dotspice_content_width()
  87. {
  88.  
  89.       // This variable is intended to be overruled from themes.
  90.       // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  91.       // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  92.       $GLOBALS['content_width'] = apply_filters('dotspice_content_width', $content_width);
  93. }
  94. add_action('after_setup_theme', 'dotspice_content_width', 0);
  95.  
  96.  
  97. /**
  98.  * Include Sripts & Styles
  99.  */
  100. function dotspice_scripts()
  101. {
  102.  
  103.       // Deregister scripts
  104.       wp_deregister_script('jquery');
  105.       wp_deregister_script('jquery-core');
  106.       wp_deregister_script('jquery-migrate');
  107.  
  108.       // Register scripts
  109.       wp_register_script('jquery-core', 'https://code.jquery.com/jquery-3.3.1.min.js', array(), null, false);
  110.       wp_register_script('jquery', false, array('jquery-core'), null, false);
  111.  
  112.       // Enqueue scripts
  113.       wp_enqueue_script('jquery');
  114.       wp_enqueue_script('bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js', array('jquery'), '', true);
  115.       wp_enqueue_script('aos-js', 'https://unpkg.com/aos@2.3.1/dist/aos.js', array('jquery'), '', true);
  116.       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);
  117.  
  118.       if (is_singular() && comments_open() && get_option('thread_comments')) {
  119.             wp_enqueue_script('comment-reply');
  120.       }
  121.       wp_enqueue_script('script', get_template_directory_uri() . '/js/script.js', array(), filemtime(get_template_directory() . '/js/script.js'), true);
  122.  
  123.       // Dequeue styles
  124.       wp_dequeue_style('wp-block-library');
  125.       wp_dequeue_style('wc-block-style');
  126.       wp_dequeue_style('cookie-consent-style');
  127.  
  128.       // Enqueue fonts
  129.       if (get_theme_mod('google_fonts')) {
  130.             wp_enqueue_style('google-fonts', esc_url(get_theme_mod('google_fonts')));
  131.       }
  132.       if (get_theme_mod('typekit_fonts')) {
  133.             wp_enqueue_style('typekit-fonts', esc_url(get_theme_mod('typekit_fonts')));
  134.       }
  135.  
  136.       // Enqueue styles
  137.       wp_enqueue_style('bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css');
  138.       wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css');
  139.       wp_enqueue_style('aos-css', 'https://unpkg.com/aos@2.3.1/dist/aos.css');
  140.       wp_enqueue_style('owl-css', 'https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css?ver=5.4.2');
  141.       wp_enqueue_style('style', get_template_directory_uri() . '/css/style.css', array(), filemtime(get_template_directory() . '/css/style.css'));
  142. }
  143. add_action('wp_enqueue_scripts', 'dotspice_scripts');
  144.  
  145.  
  146. /**
  147.  * Include Admin Sripts & Styles
  148.  */
  149. function dotspice_admin_scripts()
  150. {
  151.  
  152.       // Enqueue scripts
  153.       wp_enqueue_script('admin-script', get_template_directory_uri() . '/js/admin-script.js', array(), filemtime(get_template_directory() . '/js/admin-script.js'), true);
  154.  
  155.       // Enqueue styles
  156.       wp_enqueue_style('admin-style', get_template_directory_uri() . '/css/admin-style.css', array(), filemtime(get_template_directory() . '/css/admin-style.css'));
  157. }
  158. add_action('admin_enqueue_scripts', 'dotspice_admin_scripts');
  159.  
  160.  
  161. /**
  162.  * Register widget area.
  163.  *
  164.  * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  165.  */
  166. function dotspice_widgets_init()
  167. {
  168.       $theme_sidebars = array(
  169.             'before-navbar'          => array('tag' => 'h3',  'name' => 'Before Navbar'),
  170.             'jumbotron'              => array('tag' => false, 'name' => 'Jumbotron'),
  171.             'archive-before-content' => array('tag' => 'h3',  'name' => 'Archive Before Content'),
  172.             'sidebar'                => array('tag' => 'h3',  'name' => 'Sidebar'),
  173.             'footer'                 => array('tag' => false, 'name' => 'Footer'),
  174.       );
  175.  
  176.       if (class_exists('woocommerce')) {
  177.             $theme_sidebars = array_merge($theme_sidebars, array(
  178.                   'shop-sidebar'        => array('tag' => 'h3', 'name' => 'Shop Sidebar'),
  179.                   'shop-before-content' => array('tag' => 'h3', 'name' => 'Shop Before Content'),
  180.                   'shop-after-content'  => array('tag' => 'h3', 'name' => 'Shop After Content'),
  181.             ));
  182.       }
  183.  
  184.       foreach ($theme_sidebars as $sidebar_ID => $sidebar_data) {
  185.             register_sidebar(array(
  186.                   'name'          => sprintf(esc_html__('%s', 'dotspice'), $sidebar_data['name']),
  187.                   'id'            => $sidebar_ID,
  188.                   'description'   => esc_html__('Add widgets here.', 'dotspice'),
  189.                   'before_widget' => ($sidebar_data['tag']) ? '<section id="%1$s" class="widget %2$s">' : '<section class="widget">',
  190.                   'after_widget'  => '</section>',
  191.                   'before_title'  => ($sidebar_data['tag']) ? '<' . $sidebar_data['tag'] . ' class="widget-title">' : '',
  192.                   'after_title'   => ($sidebar_data['tag']) ? '</' . $sidebar_data['tag'] . '>' : '',
  193.             ));
  194.       }
  195. }
  196. add_action('widgets_init', 'dotspice_widgets_init');
  197.  
  198.  
  199. /**
  200.  * Enable shortcode on text widget
  201.  */
  202. add_filter('widget_text', 'do_shortcode');
  203.  
  204.  
  205. /**
  206.  * Require custom theme functions
  207.  */
  208. require_once get_template_directory() . '/inc/template-functions.php'; // Functions which enhance the theme by hooking into WordPress
  209. require_once get_template_directory() . '/inc/customizer.php';         // Customizer additions
  210. require_once get_template_directory() . '/inc/titles.php';             // Custom titles
  211. require_once get_template_directory() . '/inc/jetpack.php';            // Jetpack compatibility file.
  212. require_once get_template_directory() . '/inc/woocommerce.php';        // WooCommerce settings
  213. require_once get_template_directory() . '/inc/shortcodes.php';         // Shortcodes
  214. require_once get_template_directory() . '/inc/menu.php';               // Nav menu search and Bootstrap menu style
  215.  
  216.  
  217. /**
  218.  * Change Admin Title on Theme Editor Page
  219.  */
  220. function change_page_title_on_theme_editor($admin_title, $title)
  221. {
  222.       if (is_admin() && isset($_GET['file']) && $_GET['file'] != '') {
  223.             $full_file_name  = $_GET['file'];
  224.             $file_name_array = explode('/', $full_file_name);
  225.  
  226.             if (count($file_name_array) > 1) {
  227.                   return array_pop($file_name_array) . ' | ' . $full_file_name;
  228.             } else {
  229.                   return $full_file_name;
  230.             }
  231.       } else {
  232.             return $admin_title;
  233.       }
  234. }
  235. add_filter('admin_title', 'change_page_title_on_theme_editor', 10, 2);
  236.  
  237.  
  238. /**
  239.  * Prr
  240.  */
  241. function prr($data)
  242. {
  243.       echo "<pre>";
  244.       var_dump($data);
  245.       echo "</pre>";
  246. }
  247.  
  248.  
  249. /**
  250.  * Unique ID
  251.  */
  252. function dotspice_unique_ID()
  253. {
  254.       static $unique_ID = 0;
  255.  
  256.       return ++$unique_ID;
  257. }
  258.  
  259.  
  260. /**
  261.  * Remove AUTOP from WPCF 7
  262.  */
  263. add_filter('wpcf7_autop_or_not', '__return_false');
  264.  
  265.  
  266. /**
  267.  * Theme layout
  268.  */
  269.  
  270. // Sidebar
  271. function dotspice_sidebar_col()
  272. {
  273.       echo get_theme_mod('sidebar_col');
  274. }
  275. add_action('sidebar_col', 'dotspice_sidebar_col');
  276.  
  277. // Content
  278. function dotspice_content_col()
  279. {
  280.       echo get_theme_mod('content_col');
  281. }
  282. add_action('content_col', 'dotspice_content_col');
  283.  
  284. // Blog Post
  285. function dotspice_blog_grid_col()
  286. {
  287.       echo get_theme_mod('blog_grid_col');
  288. }
  289. add_action('blog_grid_col', 'dotspice_blog_grid_col');
  290.  
  291.  
  292. /**
  293.  * Add Page Slug to Body Class
  294.  */
  295. function dotspice_add_page_slug_body_class($classes)
  296. {
  297.       global $post;
  298.  
  299.       if (isset($post)) {
  300.             $classes[] = $post->post_type . '-' . $post->post_name;
  301.       }
  302.  
  303.       return $classes;
  304. }
  305. add_filter('body_class', 'dotspice_add_page_slug_body_class');
  306.  
  307. /**
  308.  * Paste your code here
  309.  */
  310.  
  311. add_filter('woocommerce_product_tabs', 'woo_new_product_tab');
  312. function woo_new_product_tab($tabs)
  313. {
  314.  
  315.       // Adds the new tab
  316.  
  317.       $tabs['test_tab'] = array(
  318.             'title'       => __('Parametry', 'woocommerce'),
  319.             'priority'       => 10,
  320.             'callback'       => 'woo_new_product_tab_content'
  321.       );
  322.  
  323.       return $tabs;
  324. }
  325. function woo_new_product_tab_content()
  326. {
  327.       if (!defined('ABSPATH')) {
  328.             exit; // Exit if accessed directly.
  329.       }
  330.  
  331.       global $post;
  332.  
  333.       $short_description = apply_filters('woocommerce_short_description', $post->post_excerpt);
  334.  
  335.       if (!$short_description) {
  336.             return;
  337.       }
  338.  
  339.       echo $short_description;
  340. }
  341.  
  342. /**
  343.  * Rename product data tabs
  344.  */
  345. add_filter('woocommerce_product_tabs', 'woo_rename_tabs', 98);
  346. function woo_rename_tabs($tabs)
  347. {
  348.  
  349.       $tabs['additional_information']['title'] = __('Dostawa');
  350.  
  351.       return $tabs;
  352. }
  353.  
  354. add_action('woocommerce_single_product_summary', 'single_product_price', 29);
  355. function single_product_price()
  356. {
  357.       global $product;
  358.       $price_single_product = $product->get_price();
  359.       $one_piece = $price_single_product * get_field('ilosc_metrow_w_opakowaniu');
  360.       if (get_field('ilosc_metrow_w_opakowaniu')) { ?>
  361.             <div style="border: 2px solid #0f99e3; padding: 20px; margin-bottom: 30px;">
  362.                   <p><b>INFORMACJA CENOWA</b></p>
  363.                   <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>
  364.                   <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>
  365.             </div>
  366. <?php }
  367. }
  368.  
  369. function cw_change_product_price_display($price)
  370. {
  371.       global $product;
  372.       $price_single_product = $product->get_price();
  373.       $one_piece = $price_single_product * get_field('ilosc_metrow_w_opakowaniu');
  374.  
  375.       if (get_field('ilosc_metrow_w_opakowaniu') > 0) {
  376.             $price .= ' / <small>m<sup>2</sup></small>';
  377.             return $price;
  378.       } else {
  379.             return $price;
  380.       }
  381. }
  382. add_filter('woocommerce_get_price_html', 'cw_change_product_price_display');
  383.  
  384. add_action('woocommerce_before_calculate_totals', 'custom_cart_items_price');
  385. function custom_cart_items_price($cart)
  386. {
  387.       if (is_admin() && !defined('DOING_AJAX'))
  388.             return;
  389.  
  390.       if (did_action('woocommerce_before_calculate_totals') >= 2)
  391.             return;
  392.  
  393.       foreach ($cart->get_cart() as $cart_item) {
  394.             $product_id = $cart_item['data']->get_id();
  395.             $quantity = get_post_meta($product_id, 'ilosc_metrow_w_opakowaniu', true);
  396.             if ($quantity > 0) {
  397.                   $price = $cart_item['data']->get_price();
  398.                   $cart_item['data']->set_price(floatval($price * $quantity));
  399.             } else {
  400.                   $price = $cart_item['data']->get_price();
  401.                   $cart_item['data']->set_price(floatval($price));
  402.             }
  403.       }
  404. }
  405.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement