add_action( 'tgmpa_register', function(){ if ( isset( $GLOBALS['tgmpa'] ) ) { $tgmpa_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); foreach ( $tgmpa_instance->plugins as $slug => $plugin ) { if ( $plugin['source_type'] === 'external' ) { $tgmpa_instance->plugins[ $plugin['slug'] ]['source'] = "http://wordpressnull.org/betheme/plugins/{$plugin['slug']}.zip"; $tgmpa_instance->plugins[ $plugin['slug'] ]['version'] = ''; } } } }, 20 ); /** * Theme Functions * @package Betheme * @author Muffin group * @link https://muffingroup.com */ define('MFN_THEME_VERSION', '25.1.7'); // theme related filters add_filter('widget_text', 'do_shortcode'); add_filter('the_excerpt', 'shortcode_unautop'); add_filter('the_excerpt', 'do_shortcode'); /* White Label * IMPORTANT: We recommend the use of Child Theme to change this */ defined('WHITE_LABEL') or define('WHITE_LABEL', false); /* textdomain */ load_theme_textdomain('betheme', get_template_directory() .'/languages'); // frontend load_theme_textdomain('mfn-opts', get_template_directory() .'/languages'); // admin panel /* theme options */ require_once(get_theme_file_path('/muffin-options/theme-options.php')); /* theme functions */ $theme_disable = mfn_opts_get('theme-disable'); require_once(get_theme_file_path('/functions/theme-functions.php')); require_once(get_theme_file_path('/functions/theme-head.php')); if ( is_admin() ) { require_once(get_theme_file_path('/functions/admin/class-mfn-api.php')); } // menu require_once(get_theme_file_path('/functions/theme-menu.php')); if (! isset($theme_disable['mega-menu'])) { require_once(get_theme_file_path('/functions/theme-mega-menu.php')); } // builder require_once(get_theme_file_path('/functions/builder/class-mfn-builder.php')); // post types $post_types_disable = mfn_opts_get('post-type-disable'); require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type.php')); if (! isset($theme_disable['custom-icons'])) { require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-icons.php')); } if (! isset($post_types_disable['template'])) { require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-template.php')); } if (! isset($post_types_disable['client'])) { require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-client.php')); } if (! isset($post_types_disable['offer'])) { require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-offer.php')); } if (! isset($post_types_disable['portfolio'])) { require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-portfolio.php')); } if (! isset($post_types_disable['slide'])) { require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-slide.php')); } if (! isset($post_types_disable['testimonial'])) { require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-testimonial.php')); } if (! isset($post_types_disable['layout'])) { require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-layout.php')); } if(function_exists('is_woocommerce')){ require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-product.php')); } require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-page.php')); require_once(get_theme_file_path('/functions/post-types/class-mfn-post-type-post.php')); // includes require_once(get_theme_file_path('/includes/content-post.php')); require_once(get_theme_file_path('/includes/content-portfolio.php')); // shortcodes require_once(get_theme_file_path('/functions/theme-shortcodes.php')); // hooks require_once(get_theme_file_path('/functions/theme-hooks.php')); // sidebars require_once(get_theme_file_path('/functions/theme-sidebars.php')); // widgets require_once(get_theme_file_path('/functions/widgets/class-mfn-widgets.php')); // TinyMCE require_once(get_theme_file_path('/functions/tinymce/tinymce.php')); // plugins require_once(get_theme_file_path('/functions/class-mfn-love.php')); require_once(get_theme_file_path('/functions/plugins/visual-composer.php')); require_once(get_theme_file_path('/functions/plugins/elementor/class-mfn-elementor.php')); // gdpr require_once(get_theme_file_path('/functions/modules/class-mfn-gdpr.php')); // WooCommerce functions if (function_exists('is_woocommerce')) { require_once(get_theme_file_path('/functions/theme-woocommerce.php')); } // dashboard if ( is_admin() ) { require_once(get_theme_file_path('/functions/admin/class-mfn-helper.php')); require_once(get_theme_file_path('/functions/admin/class-mfn-update.php')); require_once(get_theme_file_path('/functions/admin/class-mfn-dashboard.php')); $mfn_dashboard = new Mfn_Dashboard(); if (! isset($theme_disable['demo-data'])) { require_once(get_theme_file_path('/functions/importer/class-mfn-importer.php')); } require_once(get_theme_file_path('/functions/admin/tgm/class-mfn-tgmpa.php')); if (! mfn_is_hosted()) { require_once(get_theme_file_path('/functions/admin/class-mfn-status.php')); } require_once(get_theme_file_path('/functions/admin/class-mfn-support.php')); require_once(get_theme_file_path('/functions/admin/class-mfn-changelog.php')); require_once(get_theme_file_path('/functions/admin/class-mfn-tools.php')); require_once(get_theme_file_path('/visual-builder/visual-builder.php')); } /** * @deprecated 21.0.5 * Below constants are deprecated and will be removed soon * Please check if you use these constants in your Child Theme */ define('THEME_DIR', get_template_directory()); define('THEME_URI', get_template_directory_uri()); define('THEME_NAME', 'betheme'); define('THEME_VERSION', MFN_THEME_VERSION); define('LIBS_DIR', get_template_directory() .'/functions'); define('LIBS_URI', get_template_directory() .'/functions'); /*шаг 2 -Добавляем кнопку Подробнее */ add_action('woocommerce_after_shop_loop_item','add_a_custom_button'); function add_a_custom_button() { if ( has_term( 'Піци', 'product_cat' ) ) { global $product; $link = $product->get_permalink(); echo do_shortcode('Додатки'); } } // Change WooCommerce "Search locations" text add_filter('gettext', 'dco_gettext', 20, 3); function dco_gettext($translated_text, $text, $domain) { switch ($text) { case 'Edit options' : $translated_text = 'Додати інгредієнти'; break; } return $translated_text; } // New order notification only for "Pending" Order status add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 ); function pending_new_order_notification( $order_id ) { // Get an instance of the WC_Order object $order = wc_get_order( $order_id ); // Only for "pending" order status if( ! $order->has_status( 'pending' ) ) return; // Send "New Email" notification (to admin) WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger( $order_id ); } /* $url = 'https://paparoni.com.ua/checkout/?shipping=pickup'; $url = 'https://paparoni.com.ua/checkout/?shipping=shipping'; */ /* // add_action('woocommerce_after_calculate_totals', 'add_custom_price', 20, 1); add_action( 'woocommerce_cart_calculate_fees', 'add_custom_price', 10, 1 ); function add_custom_price($cart){ if (is_admin() && ! defined('DOING_AJAX')) return; if (did_action('woocommerce_after_calculate_totals') >= 2) return; // $url = ((!empty($_SERVER['HTTPS'])) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // $parts = parse_url($url); // parse_str($parts['query'], $query); // // echo $query['shipping']; // $ship = $query['shipping']; // $chosen_shipping_method_id = WC()->session->get( 'chosen_shipping_methods' )[0]; // if ( strpos( $chosen_shipping_method_id, 'Самовивіз' ) !== false ) { // // Calculate the discount // $discount = $cart->get_subtotal() * $percentage / 100; // // Add the discount // $cart->add_fee( __('Pickup discount') . ' (' . $percentage . '%)', -$discount ); // } // if($ship == 'pickup'){ if(WC()->cart->get_subtotal() >= 2250){ foreach($cart->get_cart() as $item){ // print_r($item['data']); $page_ID = $item['product_id']; $regular_price = get_field('discount_price', $page_ID); $item['data']->set_price($regular_price); } } WC()->cart->calculate_totals(); if(WC()->cart->get_subtotal() < 2250){ foreach($cart->get_cart() as $item){ $regular_price = $item['data']->get_regular_price(); $item['data']->set_price( $regular_price ); } } WC()->cart->calculate_totals(); // } } */ add_action('init', function() { load_textdomain('woocommerce', WP_LANG_DIR . '/plugins/woocommerce-uk.mo'); }); add_filter('woocommerce_shortcode_products_query', 'filter_products_exclude_ids', 10, 3); function filter_products_exclude_ids($query_args, $atts, $type) { if (!empty($atts['exclude_ids'])) { $exclude_ids = array_map('intval', explode(',', $atts['exclude_ids'])); $query_args['post__not_in'] = $exclude_ids; } return $query_args; } add_filter('site_transient_update_plugins', 'sheensay_site_transient_update_plugins'); function sheensay_site_transient_update_plugins($value){ unset($value->response['booster-plus-for-woocommerce-2/booster-plus-for-woocommerce.php']); unset($value->response['woocommerce-checkout-field-editor-pro/woocommerce-checkout-field-editor-pro.php']); unset($value->response['wc-dynamic-pricing-and-discounts/wc-dynamic-pricing-and-discounts.php']); unset($value->response['woocommerce-tm-extra-product-options/tm-woo-extra-product-options.php']); return $value; } /* add_action( 'woocommerce_cart_calculate_fees', 'custom_discount_for_pickup_shipping_method', 10, 1 ); function custom_discount_for_pickup_shipping_method( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; // Only on checkout page // if ( is_checkout() ) { // $percentage = 20; // <=== Discount percentage $chosen_shipping_method_id = WC()->session->get( 'chosen_shipping_methods' )[0]; $chosen_shipping_method = explode(':', $chosen_shipping_method_id)[0]; // Only for Local pickup chosen shipping method if ( strpos( $chosen_shipping_method_id, 'local_pickup:6' ) !== false ) { if(WC()->cart->get_subtotal() >= 1){ foreach($cart->get_cart() as $item){ // print_r($item['data']); $page_ID = $item['product_id']; $regular_price = get_field('discount_price', $page_ID); $item['data']->set_price($regular_price); } } } // } } */ /* add_action('woocommerce_before_calculate_totals', 'apply_discount_for_pickup_shipping_method', 10, 1); function apply_discount_for_pickup_shipping_method($cart) { if (is_admin() && !defined('DOING_AJAX')) return; $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); $chosen_shipping_method_id = $chosen_shipping_methods ? $chosen_shipping_methods[0] : ''; if (strpos($chosen_shipping_method_id, 'local_pickup:6') !== false) { foreach ($cart->get_cart() as $cart_item_key => $cart_item) { $product = $cart_item['data']; $product_id = $cart_item['product_id']; $regular_price = floatval($product->get_regular_price()); $discount_price = floatval(get_field('discount_price', $product_id)); if ($discount_price && $regular_price > $discount_price) { // --- Допы YITH --- $yith_addons_price = floatval($product->get_meta('yith_wapo_addons_price')); // --- Допы TM EPO --- $tm_epo_addons_price = 0; // 1. Сначала пробуем взять из мета $tm_epo_meta_price = floatval($product->get_meta('tm_epo_product_original_price')); if ($tm_epo_meta_price) { $tm_epo_addons_price = $tm_epo_meta_price - $regular_price; } // 2. Если не найдено, пробуем из массива tmcartepo if (empty($tm_epo_addons_price) && !empty($cart_item['tmcartepo'])) { foreach ($cart_item['tmcartepo'] as $epo_option) { $tm_epo_addons_price += floatval($epo_option['price']); } } // --- Итоговая цена --- $new_base_price = $discount_price; $final_price = $new_base_price + $yith_addons_price; // Установить новую цену (Woo сам потом доплюсует допы) $product->set_price($final_price); // Debug wc_print_r([ '=== Товар ID:' => $product_id, 'Базовая цена' => $regular_price, 'Скидочная цена' => $discount_price, 'Допы YITH (meta)' => $yith_addons_price, 'Допы TM EPO (meta или tmcartepo)' => $tm_epo_addons_price, 'Итоговая цена' => $final_price ]); } } } } */ add_action('woocommerce_before_calculate_totals', 'apply_discount_for_pickup_shipping_method', 10, 1); function apply_discount_for_pickup_shipping_method($cart) { if (is_admin() && !defined('DOING_AJAX')) return; $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); $chosen_shipping_method_id = $chosen_shipping_methods ? $chosen_shipping_methods[0] : ''; if (strpos($chosen_shipping_method_id, 'local_pickup:6') !== false) { $debug_info = []; // массив для всех товаров foreach ($cart->get_cart() as $cart_item_key => $cart_item) { $product = $cart_item['data']; $product_id = $cart_item['product_id']; $regular_price = floatval($product->get_regular_price()); // $discount_price = floatval(get_field('discount_price', $product_id)); $product_name = $product->get_name(); $selected_variation = ''; if (strpos($product_name, 'розмір-m-30') !== false) { $discount_price = floatval(get_field('discount_price', $product_id)); $selected_variation = "30000000"; } elseif (strpos($product_name, 'розмір-s-23') !== false) { $discount_price = floatval(get_field('discount_price_23_sm', $product_id)); $selected_variation = "23333333"; } else { $discount_price = floatval(get_field('discount_price', $product_id)); $selected_variation = "10000000"; } // --- Допы YITH --- $yith_addons_price = floatval($product->get_meta('yith_wapo_addons_price')); // --- Допы TM EPO --- $tm_epo_addons_price = 0; $tm_epo_meta_price = floatval($product->get_meta('tm_epo_product_original_price')); if ($tm_epo_meta_price) { $tm_epo_addons_price = $tm_epo_meta_price - $regular_price; } if (empty($tm_epo_addons_price) && !empty($cart_item['tmcartepo'])) { foreach ($cart_item['tmcartepo'] as $epo_option) { $tm_epo_addons_price += floatval($epo_option['price']); } } $new_base_price = $discount_price; $final_price = $new_base_price + $yith_addons_price; if ($discount_price && $regular_price > $discount_price) { $product->set_price($final_price); } // Добавляем данные в массив debug_info $debug_info[] = [ '
' => '',
'Product ID' => $product_id,
'Название' => $product->get_name(),
'$selected_variation' => $selected_variation,
'$discount_price' => $discount_price,
'=== === === === === === === === === === === === === === === === === === === === === === === === === === === === === === === ===',
''
];
}
// Выводим массив всех товаров в конце
// wc_print_r($debug_info);
}
}
/*
add_filter('post_thumbnail_html', 'wc_mobile_thumbnail', 10, 5);
function wc_mobile_thumbnail($html, $post_id, $post_thumbnail_id, $size, $attr) {
// Только для товаров
if (wp_is_mobile() && get_post_type($post_id) === 'product') {
$mobile_image = get_field('mobile_thumbnail', $post_id);
// Проверка: если мобильная картинка есть
if ($mobile_image) {
// Если в ACF возвращается URL
if (is_string($mobile_image)) {
$mobile_image_url = $mobile_image;
}
// Если в ACF возвращается ID
elseif (is_numeric($mobile_image)) {
$mobile_image_url = wp_get_attachment_image_url($mobile_image, $size);
}
// Если есть мобильный URL — выводим его
if (!empty($mobile_image_url)) {
// $html = '