ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

index.php (3362B)


      1 <?php
      2 
      3 require_once get_template_directory() . "/inc/woocommerce/options.php";
      4 require_once get_template_directory() . "/inc/woocommerce/list.php";
      5 
      6 add_action('customize_register', function ($wp_customize) {
      7 
      8     $panel = 'materialis_woocommerce_panel';
      9 
     10     $wp_customize->add_panel(
     11         $panel,
     12         array(
     13             'capability' => 'edit_theme_options',
     14             'title'      => esc_html__('WooCommerce Options', 'materialis'),
     15         )
     16     );
     17 
     18     $priority = 30;
     19 
     20     $wp_customize->add_section('materialis_woocommerce_product_list', array(
     21         'title'    => esc_html__('Product List Options', 'materialis'),
     22         'priority' => $priority,
     23         'panel'    => $panel,
     24     ));
     25 
     26     $wp_customize->add_section('materialis_woocommerce_general_options', array(
     27         'title'    => esc_html__('General Options', 'materialis'),
     28         'priority' => $priority,
     29         'panel'    => $panel,
     30     ));
     31 
     32     do_action('materialis_customize_register_woocommerce_section', $wp_customize, 'materialis_woocommerce_panel', $priority);
     33 
     34 }, 10, 1);
     35 
     36 
     37 add_filter('loop_shop_per_page', 'materialis_new_loop_shop_per_page', 20);
     38 
     39 function materialis_new_loop_shop_per_page($cols)
     40 {
     41     // $cols contains the current number of products per page based on the value stored on Options -> Reading
     42     // Return the number of products you wanna show per page.
     43     $cols = get_theme_mod('woocommerce_products_per_page', 12);
     44 
     45     return absint($cols);
     46 }
     47 
     48 
     49 // woocommerce_widget_shopping_cart_button_view_cart
     50 
     51 // view cart near menu
     52 
     53 function materialis_woocommerce_cart_menu_item($items, $args = false)
     54 {
     55 
     56     $isPrimaryMenu = ($args === false || (property_exists($args, 'theme_location') && $args->theme_location === "primary"));
     57 
     58     if ( ! $isPrimaryMenu) {
     59         return $items;
     60     }
     61 
     62 
     63     $cart_url = wc_get_cart_url();
     64 
     65     $cartContent = materialis_instantiate_widget("WC_Widget_Cart",
     66         array(
     67             'wrap_tag'   => 'div',
     68             'wrap_class' => 'materialis-woo-header-cart',
     69         )
     70     );
     71 
     72     $cart_id = wc_get_page_id('cart');
     73     $cartLabel= get_the_title($cart_id);
     74     
     75     $item = "<li class=\"materialis-menu-cart\"><a href=\"{$cart_url}\"><span><i class='mdi mdi-cart'></i><span class='cart-label'>{$cartLabel}</span></span></a>{$cartContent}</li>";
     76     
     77     if (materialis_get_from_memory('materialis_woocommerce_cart_menu_item_rendered')) {
     78 	    $item = "<li class=\"materialis-menu-cart-secondary\"><a href=\"{$cart_url}\"><span><i class='mdi mdi-cart'></i><span class='cart-label'>{$cartLabel}</span></span></a>{$cartContent}</li>";
     79     } else {
     80         materialis_set_in_memory('materialis_woocommerce_cart_menu_item_rendered', true);
     81     }    
     82 
     83     return $items . $item;
     84 }
     85 
     86 add_action('wp_loaded', function () {
     87 
     88     $display_near_menu = get_theme_mod('woocommerce_cart_display_near_menu', true);
     89 
     90     if (intval($display_near_menu)) {
     91         add_filter('wp_nav_menu_items', 'materialis_woocommerce_cart_menu_item', 10, 2);
     92         add_filter('materialis_nomenu_after', 'materialis_woocommerce_cart_menu_item', 10, 2);
     93     }
     94 });
     95 
     96 function materialis_get_woo_api_key()
     97 {
     98     $dummyHash = uniqid('dummy_materialis_hash');
     99 
    100     return get_theme_mod('materialis_woocommerce_api_nonce', md5($dummyHash));
    101 }
    102 
    103 function is_materialis_woocommerce_api_key_valid($key)
    104 {
    105     return $key === materialis_get_woo_api_key();
    106 }