Mary_Pieroszkiewicz

plugin - functions.php

Nov 7th, 2019
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.27 KB | None | 0 0
  1. <?php
  2.     /*
  3.         Plugin Name: Jakub Kuron Core
  4.         Description: This plugin contains PHP and Javascript custom functions needed by this page to run propertly.
  5.         Author: RISE
  6.         Author URI: riseproject.pl
  7.         Version: 1.0
  8.     */
  9.  
  10.  
  11.  
  12.     // Register custom menus
  13.     function register_custom_nav_menus() {
  14.         register_nav_menus( array(
  15.             'top-header-menu-left' => __( 'Top Header Menu (Left)', 'twentynineteen' ),
  16.             'top-header-menu-right' => __( 'Top Header Menu (Right)', 'twentynineteen' )
  17.         ) );
  18.     }
  19.  
  20.     add_action( 'after_setup_theme', 'register_custom_nav_menus' );
  21.  
  22.  
  23.  
  24.     // Remove theme menus (with priority of 20 because it have to be executed later than theme register menus (default is 10))
  25.     function remove_theme_nav_menus() {
  26.         unregister_nav_menu( 'menu-1' );
  27.         unregister_nav_menu( 'footer' );
  28.         unregister_nav_menu( 'social' );
  29.     }
  30.  
  31.     add_action( 'after_setup_theme', 'remove_theme_nav_menus', 20 );
  32.  
  33.  
  34.  
  35.     // Register custom footer widgets which will be the footer columns areas
  36.     function register_custom_footer_widget() {        
  37.         register_sidebars( 3, array(
  38.             'name' => __( 'Footer Column %d', 'twentynineteen' ),
  39.             'before_widget' => '',
  40.             'after_widget'  => '',
  41.             'before_title'  => '<h4>',
  42.             'after_title'   => '</h4>'
  43.         ) );
  44.     }
  45.  
  46.     add_action( 'widgets_init', 'register_custom_footer_widget', 20 );
  47.  
  48.  
  49.  
  50.     // Remove theme footer widget
  51.     function remove_theme_footer_widget() {
  52.         unregister_sidebar( 'sidebar-1' );
  53.     }
  54.  
  55.     add_action( 'widgets_init', 'remove_theme_footer_widget', 20 );
  56.  
  57.  
  58.  
  59.     // Load custom scripts file
  60.     function jku_js_load() {
  61.         wp_register_script( 'jakub-kuron-js', plugins_url( 'jakub-kuron-core.js', __FILE__ ), '', '1.0', true);
  62.         wp_enqueue_script( 'jakub-kuron-js' );
  63.     }
  64.  
  65.     add_action( 'wp_enqueue_scripts', 'jku_js_load' );
  66.  
  67.  
  68.  
  69.     // Create custom post taxonomies - categories
  70.     function create_cpt_categories() {
  71.         $labels = array(
  72.             'name'              => _x( 'Kategorie przepisów', 'taxonomy general name', 'textdomain' ),
  73.             'singular_name'     => _x( 'Kategoria przepisów', 'taxonomy singular name', 'textdomain' ),
  74.             'search_items'      => __( 'Szukaj kategorii', 'textdomain' ),
  75.             'all_items'         => __( 'Wszystkie kategorie', 'textdomain' ),
  76.             'parent_item'       => __( 'Nadrzędna kategoria', 'textdomain' ),
  77.             'parent_item_colon' => __( 'Nadrzędna kategoria:', 'textdomain' ),
  78.             'edit_item'         => __( 'Edytuj kategorię', 'textdomain' ),
  79.             'update_item'       => __( 'Zaktualizuj kategorię', 'textdomain' ),
  80.             'add_new_item'      => __( 'Dodaj nową kategorię', 'textdomain' ),
  81.             'new_item_name'     => __( 'Dodaj nową nazwę kategorii', 'textdomain' ),
  82.             'menu_name'         => __( 'Kategorie przepisów', 'textdomain' ),
  83.         );
  84.  
  85.         $args = array(
  86.             'hierarchical'      => true,
  87.             'labels'            => $labels,
  88.             'show_ui'           => true,
  89.             'public'            => true,
  90.             'has_archive'       => true,
  91.             'show_admin_column' => true,
  92.             'query_var'         => true,
  93.             'rewrite'           => array( 'slug' => 'przepisy', 'with_front' => true ),
  94.         );
  95.  
  96.         register_taxonomy( 'kategorie-przepisow', array( 'przepisy' ), $args );
  97.     }
  98.  
  99.     add_action( 'init', 'create_cpt_categories', 0 );
  100.  
  101.  
  102.  
  103.     // Create custom post taxonomies - tags
  104.     function create_cpt_tags() {
  105.         $labels = array(
  106.             'name'              => _x( 'Tagi przepisów', 'taxonomy general name', 'textdomain' ),
  107.             'singular_name'     => _x( 'Tag przepisów', 'taxonomy singular name', 'textdomain' ),
  108.             'search_items'      => __( 'Szukaj tagów', 'textdomain' ),
  109.             'all_items'         => __( 'Wszystkie tagi', 'textdomain' ),
  110.             'parent_item'       => null,
  111.             'parent_item_colon' => null,
  112.             'edit_item'         => __( 'Edytuj tag', 'textdomain' ),
  113.             'update_item'       => __( 'Zaktualizuj tag', 'textdomain' ),
  114.             'add_new_item'      => __( 'Dodaj nowy tag', 'textdomain' ),
  115.             'new_item_name'     => __( 'Dodaj nową nazwę tagu', 'textdomain' ),
  116.             'menu_name'         => __( 'Tagi przepisów', 'textdomain' ),
  117.         );
  118.  
  119.         $args = array(
  120.             'hierarchical'      => false,
  121.             'labels'            => $labels,
  122.             'show_ui'           => true,
  123.             'public'            => true,
  124.             'show_admin_column' => true,
  125.             'update_count_callback' => '_update_post_term_count',
  126.             'query_var'         => true,
  127.             'rewrite'           => array( 'slug' => 'tagi', 'with_front' => true ),
  128.         );
  129.  
  130.         register_taxonomy( 'tagi-przepisow', array( 'przepisy' ), $args );
  131.     }
  132.  
  133.     add_action( 'init', 'create_cpt_tags', 0 );
  134.  
  135.  
  136.     // Custom post types copied from the old site
  137.     function create_przepis() {
  138.         register_post_type( 'przepisy',
  139.             array(
  140.                 'labels' => array(
  141.                     'name' => 'Przepisy',
  142.                     'singular_name' => 'Przepis',
  143.                     'add_new' => 'Dodaj nowy',
  144.                     'add_new_item' => 'Dodaj nowy Przepis',
  145.                     'edit' => 'Edytuj',
  146.                     'edit_item' => 'Edytuj Przepis',
  147.                     'new_item' => 'Nowy Przepis',
  148.                     'view' => 'Zobacz',
  149.                     'view_item' => 'Zobacz Przepis',
  150.                     'search_items' => 'Szukaj Przepisów',
  151.                     'not_found' => 'Nie znaleziono',
  152.                     'not_found_in_trash' => 'Nie znaleziono w koszu',
  153.                     'parent' => 'Parent Przepis'
  154.                 ),
  155.  
  156.                 'public'        => true,
  157.                 'hierarchical'  => true,
  158.                 'show_ui'       => true,
  159.                 'has_archive'   => true,
  160.                 'menu_position' => 4,
  161.                 'supports'      => array( 'title', 'editor', 'thumbnail', 'comments', 'custom-fields' ),
  162.                 'taxonomies'    => array( 'kategorie-przepisow', 'tagi-przepisow' ),
  163.                 'rewrite'       => array( 'slug' => 'przepisy/%kategorie-przepisow%', 'with_front' => true )
  164.             )
  165.         );
  166.     }
  167.  
  168.     add_action( 'init', 'create_przepis' );
  169.  
  170.  
  171.  
  172. function wpa_course_post_link( $post_link, $id = 0 ){
  173.     $post = get_post($id);  
  174.     if ( is_object( $post ) ){
  175.         $terms = wp_get_object_terms( $post->ID, 'kategorie-przepisow' );
  176.         if( $terms ){
  177.             return str_replace( '%kategorie-przepisow%' , $terms[0]->slug , $post_link );
  178.         }
  179.     }
  180.     return $post_link;  
  181. }
  182. add_filter( 'post_type_link', 'wpa_course_post_link', 1, 3 );
  183.  
  184.  
  185.     /*
  186.     function create_wideo() {
  187.         register_post_type( 'video',
  188.             array(
  189.                 'labels' => array(
  190.                     'name' => 'Wideo',
  191.                     'singular_name' => 'Wideo',
  192.                     'add_new' => 'Dodaj nowy',
  193.                     'add_new_item' => 'Dodaj nowy Wideo',
  194.                     'edit' => 'Edytuj',
  195.                     'edit_item' => 'Edytuj Wideo',
  196.                     'new_item' => 'Nowy Wideo',
  197.                     'view' => 'Zobacz',
  198.                     'view_item' => 'Zobacz Wideo',
  199.                     'search_items' => 'Szukaj Przepisów',
  200.                     'not_found' => 'Nie znaleziono',
  201.                     'not_found_in_trash' => 'Nie znaleziono w koszu',
  202.                     'parent' => 'Parent Wideo'
  203.                 ),
  204.  
  205.                 'public' => true,
  206.                 'menu_position' => 5,
  207.                 'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
  208.                 'taxonomies' => array('category', 'post_tag')
  209.             )
  210.         );
  211.     }
  212.  
  213.     add_action( 'init', 'create_wideo' );
  214.  
  215.  
  216.  
  217.     // Unregister videos post type
  218.     function kill_video() {
  219.         unregister_post_type( 'video' );
  220.     }
  221.  
  222.     add_action( 'init', 'kill_video' );
  223.     */
  224.  
  225.  
  226.  
  227.     // Stop wordpress from adding p tags everywhere
  228.     remove_filter( 'the_content', 'wpautop' );
  229.     remove_filter( 'the_excerpt', 'wpautop' );
  230.  
  231.  
  232.  
  233.     // List 1st level post categories executed by the shortcode
  234.     function cpt_categories_cloud_shortcode() {
  235.         // Get the taxonomy's terms
  236.         $terms = get_terms( array(
  237.             'taxonomy'   => 'kategorie-przepisow',
  238.             'hide_empty' => true,
  239.             'parent'     => 0
  240.         ));
  241.  
  242.         // Check if any term exists
  243.         if ( !empty( $terms ) && is_array( $terms ) ) {
  244.             $output = '<ul class="jku-categories-cloud-wrapper">';
  245.             foreach ( $terms as $term ) {
  246.                 $output .= '<li><a href="' . esc_url(get_term_link( $term )) . '">' . $term->name . '</a></li>';
  247.             }
  248.             $output .= '</ul>';
  249.         }
  250.        
  251.         return $output;
  252.     }
  253.  
  254.     add_shortcode( 'cpt-categories-cloud', 'cpt_categories_cloud_shortcode' );
  255.  
  256.  
  257.  
  258.     // List 2nd level post categories executed by the shortcode
  259.     /*
  260.     function cpt_categories_cloud_shortcode_children() {
  261.         // Get the taxonomy's terms
  262.         $terms = get_terms( array(
  263.             'taxonomy'   => 'kategorie-przepisow',
  264.             'hide_empty' => true,
  265.             'parent'     => 0
  266.         ));
  267.  
  268.         // Check if any term exists
  269.         if ( !empty( $terms ) && is_array( $terms ) ) {
  270.             $output = '<ul class="jku-categories-cloud-wrapper">';
  271.             foreach ( $terms as $term ) {
  272.                 $output .= '<li><a href="' . esc_url(get_term_link( $term )) . '">' . $term->name . '</a></li>';
  273.             }
  274.             $output .= '</ul>';
  275.         }
  276.        
  277.         return $output;
  278.     }
  279.  
  280.     add_shortcode( 'cpt-categories-cloud', 'cpt_categories_cloud_shortcode' );
  281.     */
  282.  
  283.  
  284.  
  285.     // List random recipes shortcode
  286.     function list_recipes_shortcode() {
  287.         $args = array(
  288.             'post_type'      => 'przepisy',
  289.             'orderby'        => 'rand',
  290.             'posts_per_page' => '8',
  291.             'meta_query' => array(
  292.                 array(
  293.                  'key' => '_thumbnail_id',
  294.                  'compare' => 'EXISTS'
  295.                 )
  296.             )
  297.         );
  298.  
  299.         $testimonials = new WP_Query($args);
  300.        
  301.         $output = '<div class="jku-post-grid-wrapper jku-similar-posts-wrapper">';
  302.  
  303.             while ($testimonials->have_posts()) : $testimonials->the_post();
  304.                 $postid = get_the_ID();
  305.        
  306.                 $output .= '<div class="jku-post-grid-item">';
  307.                     if ( has_post_thumbnail() ) {
  308.                         $output .= '<a class="jku-image-placeholder" href="' . get_permalink() . '" style="background-image: url(' . get_the_post_thumbnail_url($postid, 'full') . ');">';
  309.                     } else {
  310.                         $output .= '<a class="jku-image-placeholder" href="' . get_permalink() . '">';
  311.                     }
  312.                     if ( has_term( 'wideo', 'kategorie-przepisow' ) ) {
  313.                         $output .= '<img class="jku-video-post-icon" src="/wp-content/themes/jakub-kuron/svg/jkuron-icon-video0.svg" /></img>';
  314.                     }
  315.                     $output .= '</a>';
  316.        
  317.                     $output .= '<h5 class="jku-post-grid-categories">';
  318.                         $term_list = wp_get_post_terms($postid, 'kategorie-przepisow', array("fields" => "all"));  
  319.                         foreach($term_list as $term_single) {
  320.                             $output .= '<span><a href="' . esc_url(get_term_link( $term_single )) . '">' . $term_single->name . '</a></span>';
  321.                         }
  322.                     $output .= '</h5>';
  323.        
  324.                     $output .= '<a class="jku-post-grid-title" href="' . get_permalink() . '">';
  325.                         $output .= '<h3>' . get_the_title() . '</h3>';
  326.                     $output .= '</a>';
  327.                 $output .= '</div>';
  328.             endwhile;
  329.  
  330.         $output .= '</div>';
  331.  
  332.         wp_reset_postdata();
  333.        
  334.         return $output;
  335.     }
  336.  
  337.     add_shortcode( 'list-recipes', 'list_recipes_shortcode' );
  338.  
  339.  
  340.  
  341.     // Enable running shortcodes in widgets
  342.     add_filter( 'widget_text', 'do_shortcode' );
  343.  
  344.  
  345.  
  346.     // Change the except length
  347.     function change_excerpt_length( $length ) {
  348.         return 20;
  349.     }
  350.  
  351.     add_filter( 'excerpt_length', 'change_excerpt_length', 999 );
  352.  
  353.  
  354.    
  355.     // Change ending of the excerpt
  356.     function change_excerpt_more( $more ) {
  357.         return '..';
  358.     }
  359.  
  360.     add_filter( 'excerpt_more', 'change_excerpt_more' );
  361.  
  362.  
  363.  
  364.     // List posts shortcode
  365.     function list_posts_shortcode() {
  366.         $args = array(
  367.             'post_type'      => 'post',
  368.             'orderby'        => 'desc',
  369.             'posts_per_page' => '2',
  370.             'meta_query' => array(
  371.                 array(
  372.                  'key' => '_thumbnail_id',
  373.                  'compare' => 'EXISTS'
  374.                 )
  375.             )
  376.         );
  377.        
  378.         $posts = new WP_Query($args);
  379.  
  380.         $output = '<div class="jku-post-grid-items-wrapper">';
  381.        
  382.             while ($posts->have_posts()) : $posts->the_post();
  383.  
  384.                 $output .= '<div class="jku-post-grid-item">';
  385.  
  386.                     if ( has_post_thumbnail() ) {
  387.                         $output .= '<a class="jku-post-grid-image" href="' . get_permalink() . '">' . get_the_post_thumbnail() . '</a>';
  388.                     }
  389.                     $output .= '<h5 class="jku-post-grid-date">' . get_the_date( 'j F Y' ) . '</h5>';
  390.                     $output .= '<a class="jku-post-grid-title" href="' . get_permalink() . '"><h3>' . get_the_title() . '</h3></a>';
  391.                     $output .= '<p>' . get_the_excerpt() . '</p>';
  392.  
  393.                 $output .= '</div>';
  394.        
  395.             endwhile;
  396.  
  397.         $output .= '</div>';
  398.  
  399.        
  400.         wp_reset_postdata();
  401.        
  402.         return $output;
  403.     }
  404.  
  405.     add_shortcode( 'list-posts', 'list_posts_shortcode' );
  406.  
  407.  
  408.  
  409.     //
  410.     // WooCommerce functions
  411.     //
  412.  
  413.  
  414.  
  415.     // Remove WooCommerce image gallery features
  416.     function remove_zoom_lightbox_theme_support() {
  417.         remove_theme_support( 'wc-product-gallery-zoom' );
  418.         remove_theme_support( 'wc-product-gallery-lightbox' );
  419.         remove_theme_support( 'wc-product-gallery-slider' );
  420.     }
  421.  
  422.     add_action( 'after_setup_theme', 'remove_zoom_lightbox_theme_support', 100000 );
  423.  
  424.  
  425.  
  426.     // Remove link from single product image
  427.     function remove_product_image_link( $html, $post_id ) {
  428.         return preg_replace( "!<(a|/a).*?>!", '', $html );
  429.     }
  430.  
  431.     add_filter( 'woocommerce_single_product_image_thumbnail_html', 'remove_product_image_link', 10, 2 );
  432.  
  433.  
  434.  
  435.     // Remove WooCommerce resources from non woocommerce pages
  436.     function remove_woocommerce_scripts() {
  437.         if ( function_exists( 'is_woocommerce' ) ) {
  438.             if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
  439.                 remove_action( 'wp_enqueue_scripts', [WC_Frontend_Scripts::class, 'load_scripts'] );
  440.                 remove_action( 'wp_print_scripts', [WC_Frontend_Scripts::class, 'localize_printed_scripts'], 5 );
  441.                 remove_action( 'wp_print_footer_scripts', [WC_Frontend_Scripts::class, 'localize_printed_scripts'], 5 );
  442.             }
  443.         }
  444.     }
  445.  
  446.     add_action( 'template_redirect', 'remove_woocommerce_scripts', 100000 );
  447.  
  448.  
  449.  
  450.     // Remove WooCommerce styles
  451.     add_filter( 'woocommerce_enqueue_styles', '__return_false', 100000 );
  452.    
  453.  
  454.  
  455.     // Remove other not required styles
  456.     function remove_other_css() {
  457.        
  458.         // WooCommerce
  459.         wp_dequeue_style('wc-block-style');
  460.         wp_deregister_style('wc-block-style');
  461.         wp_dequeue_style('woocommerce-inline');
  462.         wp_deregister_style('woocommerce-inline');
  463.        
  464.         // WP Includes
  465.         wp_dequeue_style('wp-block-library');
  466.         wp_deregister_style('wp-block-library');
  467.         wp_dequeue_style('wp-block-library-theme');
  468.         wp_deregister_style('wp-block-library-theme');
  469.        
  470.         // Twenty Nineteen print stylesheet
  471.         wp_dequeue_style('twentynineteen-print-style');
  472.         wp_deregister_style('twentynineteen-print-style');
  473.        
  474.         // Cookie Notice
  475.         wp_dequeue_style('cookie-notice-front');
  476.         wp_deregister_style('cookie-notice-front');
  477.        
  478.         // Contact Form 7
  479.         wp_dequeue_style('contact-form-7');
  480.         wp_deregister_style('contact-form-7');
  481.        
  482.         // Post Grid
  483.         wp_dequeue_style('post_grid_style');
  484.         wp_deregister_style('post_grid_style');
  485.         wp_dequeue_style('font-awesome-5');
  486.         wp_deregister_style('font-awesome-5');
  487.         wp_dequeue_style('style.skins');
  488.         wp_deregister_style('style.skins');
  489.         wp_dequeue_style('style.layout');
  490.         wp_deregister_style('style.layout');
  491.         wp_dequeue_style('style.animate');
  492.         wp_deregister_style('style.animate');
  493.     }
  494.  
  495.     add_action( 'wp_enqueue_scripts','remove_other_css', 100000 );
  496.  
  497.  
  498.  
  499.     // Add custom css to WooCommerce pages
  500.     function register_custom_woo_style() {
  501.         if ( function_exists( 'is_woocommerce' ) ) {
  502.             if ( is_woocommerce() || is_cart() || is_checkout() ) {
  503.                 wp_register_style( 'jkuron-woo-styles', '/wp-content/themes/jakub-kuron/woocommerce/style.css' );
  504.                 wp_enqueue_style( 'jkuron-woo-styles' );
  505.             }
  506.         }
  507.     }
  508.  
  509.     add_action( 'wp_enqueue_scripts', 'register_custom_woo_style' );
  510.  
  511.  
  512.  
  513.     // Change posts per page Woo
  514.     function redefine_products_per_page( $per_page ) {
  515.         $per_page = 9;
  516.         return $per_page;
  517.     }
  518.  
  519.     add_filter( 'loop_shop_per_page', 'redefine_products_per_page', 100000 );
  520.  
  521.  
  522.  
  523.     // Register custom footer widgets which will be the footer columns areas
  524.     function register_woocommerce_sidebar() {
  525.         register_sidebar( array(
  526.             'name' => __( 'WooCommerce Shop Page Sidebar', 'twentynineteen' ),
  527.             'id' => 'woocommerce-shop-page-sidebar',
  528.             'before_widget' => '',
  529.             'after_widget'  => '',
  530.             'before_title'  => '',
  531.             'after_title'   => ''
  532.         ) );
  533.     }
  534.  
  535.     add_action( 'widgets_init', 'register_woocommerce_sidebar', 20 );
  536.  
  537.  
  538.  
  539.     // Breadcrumbs: Change home label
  540.     function wcc_change_breadcrumb_home_text( $defaults ) {
  541.         $defaults['home'] = 'Jakub Kuroń';
  542.         return $defaults;
  543.     }
  544.  
  545.     add_filter( 'woocommerce_breadcrumb_defaults', 'wcc_change_breadcrumb_home_text' );
  546.  
  547.  
  548.  
  549.     // Breadcrumbs: Change home link
  550.     function woo_custom_breadrumb_home_url() {
  551.         return '/';
  552.     }
  553.  
  554.     add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
  555.  
  556.  
  557.  
  558.     // Breadcrumbs: Change delimiter
  559.     function wcc_change_breadcrumb_delimiter( $defaults ) {
  560.         $defaults['delimiter'] = ' <span class="jku-separator"></span> ';
  561.         return $defaults;
  562.     }
  563.  
  564.     add_filter( 'woocommerce_breadcrumb_defaults', 'wcc_change_breadcrumb_delimiter' );
  565.  
  566.  
  567.  
  568.     // WooCommerce - add plus / minus quantity buttons
  569.     function display_quantity_buttons() {
  570.         echo '<div class="jku-quantity-buttons-wrapper"><button type="button" class="plus" >+</button><button type="button" class="minus" >-</button></div>';
  571.     }
  572.  
  573.     add_action( 'woocommerce_after_add_to_cart_quantity', 'display_quantity_buttons' );
  574.  
  575.     function add_cart_quantity_plus_minus() {
  576.         if ( ! is_product() ) return;
  577.         ?>
  578.             <script type="text/javascript">
  579.                 jQuery(document).ready(function($){  
  580.                     $('form.cart').on( 'click', 'button.plus, button.minus', function() {
  581.  
  582.                         // Get current quantity values
  583.                         var qty  = $( this ).closest( 'form.cart' ).find( '.qty' );
  584.                         var val  = parseFloat(qty.val());
  585.                         var max  = parseFloat(qty.attr( 'max' ));
  586.                         var min  = parseFloat(qty.attr( 'min' ));
  587.                         var step = parseFloat(qty.attr( 'step' ));
  588.  
  589.                         // Change the value if plus or minus
  590.                         if ( $( this ).is( '.plus' ) ) {
  591.                             if ( max && ( max <= val ) ) {
  592.                                 qty.val( max );
  593.                             } else {
  594.                                 qty.val( val + step );
  595.                             }
  596.                         } else {
  597.                             if ( min && ( min >= val ) ) {
  598.                                 qty.val( min );
  599.                             } else if ( val > 1 ) {
  600.                                 qty.val( val - step );
  601.                             }
  602.                         }
  603.  
  604.                     });
  605.                 });
  606.             </script>
  607.         <?php
  608.     }
  609.  
  610.     add_action( 'wp_footer', 'add_cart_quantity_plus_minus' );
  611.  
  612.  
  613.  
  614.     // Changing the minimum and maximum quantity for all the WooCommerce products
  615.     function woocommerce_quantity_input_min_callback( $min, $product ) {
  616.         $min = 1;  
  617.         return $min;
  618.     }
  619.  
  620.     add_filter( 'woocommerce_quantity_input_min', 'woocommerce_quantity_input_min_callback', 10, 2 );
  621.  
  622.     function woocommerce_quantity_input_max_callback( $max, $product ) {
  623.         $max = 99;  
  624.         return $max;
  625.     }
  626.  
  627.     add_filter( 'woocommerce_quantity_input_max', 'woocommerce_quantity_input_max_callback', 10, 2 );
  628.  
  629.  
  630.  
  631.     // Remove opening terms and conditions in the same page. Open in the new tab instead.
  632.     function disable_wc_terms_toggle() {
  633.         wp_add_inline_script( 'wc-checkout', "jQuery( document ).ready( function() { jQuery( document.body ).off( 'click', 'a.woocommerce-terms-and-conditions-link' ); } );" );
  634.     }
  635.  
  636.     add_action( 'wp_enqueue_scripts', 'disable_wc_terms_toggle', 1000 );
  637.  
  638.  
  639.  
  640.     // Modify image width theme support
  641.     function modify_theme_support() {
  642.         $theme_support = get_theme_support( 'woocommerce' );
  643.         $theme_support = is_array( $theme_support ) ? $theme_support[0] : array();
  644.  
  645.         $theme_support['single_image_width'] = 660;
  646.         $theme_support['thumbnail_image_width'] = 660;
  647.  
  648.         remove_theme_support( 'woocommerce' );
  649.         add_theme_support( 'woocommerce', $theme_support );
  650.     }
  651.  
  652.     add_action( 'after_setup_theme', 'modify_theme_support', 10 );
  653.  
  654. ?>
Advertisement
Add Comment
Please, Sign In to add comment