Skip to content

Instantly share code, notes, and snippets.

View DxDiagDx's full-sized avatar
:octocat:

Evgeny Lukin DxDiagDx

:octocat:
View GitHub Profile
@DxDiagDx
DxDiagDx / functions.php
Created February 3, 2021 15:16
Woo: изменить текст «Доступно для предзаказа» / Change "available on backorder" WooCommerce text
<?php
add_filter( 'woocommerce_get_availability', 'my_woocommerce_get_availability' );
function my_woocommerce_get_availability( $availability ) {
if ( $availability['class'] == 'available-on-backorder' ) {
$availability['availability'] = 'Под заказ';
}
return $availability;
}
@DxDiagDx
DxDiagDx / functions.php
Last active February 3, 2021 15:18
Woo: автообновление корзины / auto_update_cart
<?php
// Автообновление корзины
add_action( 'wp_print_footer_scripts', 'auto_update_cart' );
function auto_update_cart(){
?>
<script type="text/javascript">
jQuery( function( $ ) {
$( 'body' ).on( 'change', '.qty', function() { // поле с количеством имеет класс .qty
@DxDiagDx
DxDiagDx / functions.php
Last active February 3, 2021 15:19
Woo: переименовать кнопку «Добавить в корзину»
<?php
// Add to cart
add_filter( 'woocommerce_product_single_add_to_cart_text', 'tb_woo_custom_cart_button_text' );
add_filter( 'woocommerce_product_add_to_cart_text', 'tb_woo_custom_cart_button_text' );
function tb_woo_custom_cart_button_text() {
return __( 'Положить товар в Корзину', 'woocommerce' );
}
@DxDiagDx
DxDiagDx / functions.php
Last active February 3, 2021 15:19
Woo: вывод скидки в карточке товара
<?php
// Добавляем значение скидки рядом с ценой у товаров (в рублях / в процентах )
add_action( 'woocommerce_single_product_summary', 'usota_single_on_sale', 10 );
function usota_single_on_sale() {
global $product;
if ( $product->is_on_sale() ) {
// Экономия в процентах
//$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
@DxDiagDx
DxDiagDx / functions.php
Last active February 3, 2021 15:19
Woo: сохранение выбранной сортировки при переходе в другую категорию
<?php
add_filter('term_link', 'truemisha_ne_sbrasyvat_filtr', 10, 3);
function truemisha_ne_sbrasyvat_filtr( $url, $term, $taxonomy ) {
// сначала мы проверяем, присутствует у нас в данный момент сортировка
$orderby = ! empty( $_GET[ 'orderby' ] ) ? $_GET[ 'orderby' ] : '';
// если присутствует, то добавляем её в конечный урл
if( $orderby ) {
return add_query_arg( 'orderby', $orderby, $url );
} else {
@DxDiagDx
DxDiagDx / functions.php
Last active February 3, 2021 15:20
Storefront: включить/отключить/поменять местами блоки в шапке | Header element move
<?php
/* ========== Header ========== */
/* Storefront: включить/отключить/поменять местами блоки в шапке | Header element move */
add_action('init', 'remove_storefront_header_search_init');
function remove_storefront_header_search_init() {
remove_action('storefront_header', 'storefront_site_branding', 20); // Логотип
remove_action('storefront_header', 'storefront_secondary_navigation', 30); // Дополнительное меню
remove_action('storefront_header', 'storefront_product_search', 40); // Поиск
remove_action('storefront_header', 'storefront_primary_navigation', 50); // Основное меню
@DxDiagDx
DxDiagDx / index.html
Last active February 3, 2021 15:21
Facebook: скрипт передачи цели в пиксель facebook
// Пиксель FB должен быть обяательно установлен
//.button_class — класс кнопки, нажатие которой нужно отследить
// Пождробнее на https://developers.facebook.com/docs/facebook-pixel/advanced
<script>
jQuery(document).ready(function () {
jQuery('.button_class').click(function () {
fbq('track', 'CompleteRegistratipn');
})
})
@DxDiagDx
DxDiagDx / functions.php
Last active February 3, 2021 15:28
Woo: отключить расчёт доставки в корзине
<?php
function disable_shipping_calc_on_cart( $show_shipping ) {
if( is_cart() ) {
return false;
}
return $show_shipping;
}
add_filter( 'woocommerce_cart_ready_to_calc_shipping', 'disable_shipping_calc_on_cart', 99 );
@DxDiagDx
DxDiagDx / functions.php
Last active February 3, 2021 15:33
Woo: скрыть варианты сортировки
<?php
add_filter( 'woocommerce_default_catalog_orderby_options', 'truemisha_remove_orderby_options' );
add_filter( 'woocommerce_catalog_orderby', 'truemisha_remove_orderby_options' );
function truemisha_remove_orderby_options( $sortby ) {
unset( $sortby[ 'popularity' ] ); // по популярности
unset( $sortby[ 'rating' ] ); // по рейтингу
unset( $sortby[ 'date' ] ); // Сортировка по более позднему
@DxDiagDx
DxDiagDx / functions.php
Last active February 3, 2021 15:33
Woo: Добавить сортировку «В случайном порядке»
<?php
// Добавить сортировку «В случайном порядке»
add_filter( 'woocommerce_default_catalog_orderby_options', 'truemisha_custom_orderby_option' );
add_filter( 'woocommerce_catalog_orderby', 'truemisha_custom_orderby_option' );
function truemisha_custom_orderby_option( $sortby ) {
$sortby['randomly'] = 'В случайном порядке';
return $sortby;
}