This artickles will help with it:
wpml.org/documentation/getting-started-guide/language-setup/deleting-languages-and-plugin-data-by-doing-a-wpml-reset-on-your-site/
If you have time out after attempt to delete language, read this:
wpml.org/forums/topic/how-to-delete-language-content-from-database/
sql queries works quickly.
Временные метки wp
Если страницы сайта долго загружаются, то причина может быть в теме оформления wp.
Для анализа скорости работы темы оформления можно добавлять код, который будет логировать временные метки.
И на основе анализа этих меток можно будет оценить время выполнения php с момента вызова functions.php до момента вызова последней строки в footer.php
1 2 3 4 5 6 |
<?php if (function_exists('wc_get_logger') && is_user_logged_in() && str_contains($_SERVER['REQUEST_URI'], 'your uri here') ) { $logger = wc_get_logger(); $context = array( 'source' => 'slow log' ); $err_msg = 'start header.php '.microtime(true); $logger->info( $err_msg, $context ); }?> |
Файл лога будет доступен в админке в табе логов woocommerce.
В коде добавлен адрес конкретной страницы и условие авторизации пользователя, чтобы другие посетители не попадали в лог.
Обновление мини корзины после ajax добавления в корзину
Скрипт ajax_add_to_cart.js имеет объект response(можно вывести в console.log() для понимания что приходит в ответ), который возвращается после запроса.
При успешном добавлении в нем будет html из шаблона mini-cart.php обернутый в класс widget_shopping_cart_content. Если в шаблоне такой обертки нет, то html миникарт не будет обновляться и будет хранить данные, полученные при загрузке страницы.
При этом в настройках woocommerce должна стоять галочка «Enable ajax on archive, shop pages»
Show regular price in minicart
This code for showing regular price for each product in minicart and subtotal sum. Work with simple and variable products. For bundle products — need corrections.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
function display_regular_price_in_mini_cart( $item_data, $cart_item ) { $product = wc_get_product( $cart_item['product_id'] ); $quantity = $cart_item['quantity']; if ( $product->is_type( 'variable' ) ) { $variation_id = $cart_item['variation_id']; $variation = wc_get_product( $variation_id ); $regular_price = $variation->get_regular_price(); } else { $regular_price = $product->get_regular_price(); } if ( $regular_price ) { $item_data[] = array( 'key' => 'regular_price', 'value' => '<span class="test_quantity">'.$quantity.' × '.'</span><del>'.wc_price( $regular_price ).'</del><br/>', 'display' => '', ); } return $item_data; } add_filter( 'woocommerce_get_item_data', 'display_regular_price_in_mini_cart', 10, 2 ); function show_subtotal_with_regular_prices( $subtotal ) { $cart = WC()->cart->get_cart(); $subtotal_sale = $subtotal; $subtotal = 0; foreach ( $cart as $cart_item_key => $cart_item ) { $product_id = $cart_item['product_id']; $product = wc_get_product( $cart_item['product_id'] ); $quantity = $cart_item['quantity']; if ( $product->is_type( 'variable' ) ) { $variation_id = $cart_item['variation_id']; $variation = wc_get_product( $variation_id ); $regular_price = $variation->get_regular_price(); } else { $regular_price = $product->get_regular_price(); } $subtotal += $regular_price * $quantity; } return $subtotal_sale.'<del>'.wc_price($subtotal).'</del>'; } add_filter( 'woocommerce_cart_subtotal', 'show_subtotal_with_regular_prices' ); |
Add your custom log to woocommerce
You may use this code to save custom information in wp loop
1 2 3 4 5 |
if (function_exists('wc_get_logger')) { $logger = wc_get_logger(); $context = array( 'source' => 'Log name here' ); $logger->info( $err_msg, $context ); } |
It will be available in woocommerce Status-> Logs tab
104: Connection reset by peer
Если при попытке открыть страницу аналитики woocommerce возникает ошибка 502 Bad Gateway, а в логе сервера при этом сообщение
1 |
104: Connection reset by peer |
То одной из возможных причин может быть конфликт плагинов. Конкретно у меня была проблема с WooCommerce Google Product Feed. После его деактивации страница начинала работать как надо.
Если дело не в этом плагине, то нужно попробовать поочередно отключать их все. Также необходимо в логе смотреть ошибки по php — сама ошибка говорит о том, что nginx не смог получить корректный ответ от php-fpm
Добавить класс к карточке товара
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// Фильтр для добавления класса к карточке товара function add_custom_class_to_product_card($classes) { global $product; $product_class_settings = get_option('product_class_settings'); $product_ids = isset($product_class_settings['product_ids']) ? $product_class_settings['product_ids'] : ''; if ($product_ids) { $product_ids = explode(',', $product_ids); $product_ids = array_map('trim', $product_ids); if (in_array($product->get_id(), $product_ids)) { $classes[] = 'hide-regular-price'; // Можно заменить 'hide-regular-price' на имя класса, которое вы хотите добавить к карточке товара } } return $classes; } add_filter('woocommerce_post_class', 'add_custom_class_to_product_card'); |
Woocommerce terms and conditions in iframe
1 2 3 4 5 6 7 8 |
function design_woocommerce_checkout_terms_and_conditions() { remove_action('woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30); } if ((!defined('MAIN_SITE') || !MAIN_SITE) && !in_array(COUNTRY_NAME, ['Switzerland'])) { add_action('wp', 'design_woocommerce_checkout_terms_and_conditions'); } |
Woocommerce получить список урлов товаров
Иногда необходимо быстро получить список адресов страниц всех опубликованных на сайте товаров. Для этого необходимо выполнить данный php скрипт, который можно разместить в корне сайта.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php include( 'wp-load.php' ); // Setup your custom query $args = [ 'post_type' => ['product'/*, 'post', 'page'*/], 'posts_per_page' => -1, 'post_status' => 'publish' ]; $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); global $post; $product = wc_get_product( $post->ID ); $permalink = $product->get_permalink(); echo $permalink.'<br/>'; endwhile; wp_reset_query(); // Remember to reset ?> |
Установить sku товару и вариациям
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?php include( 'wp-load.php' ); $list = []; $args = [ 'post_type' => ['product'/*, 'post', 'page'*/], 'posts_per_page' => -1, 'post_status' => 'publish' ]; $loop = new WP_Query( $args ); $list = array(); while ( $loop->have_posts() ) : $loop->the_post(); global $post; $product = wc_get_product( $post->ID ); $max_sku = '100000000'.time(); if(empty($product->get_sku())){ $product->set_sku($max_sku); } if( $product->is_type('variable')) { $children_ids = $product->get_children(); foreach( $children_ids as $child_id ){ $max_sku = '100000000'.generateRandomString().time(); $variation = wc_get_product($child_id); if(get_post_meta($variation->get_id(), '_sku', true) === ''){ $variation->set_sku( $max_sku ); $variation->save(); } } } endwhile; wp_reset_query(); // Remember to reset ?> |