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 May 23, 2022 07:01
WP StoreFront: как добавить Google Fonts
/* Меняем шрифт на Google Fonts */
add_action( 'storefront_header', 'add_google_fonts_storefront_header', 40 );
function add_google_fonts_storefront_header() {
?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,200;8..144,300;8..144,400;8..144,500;8..144,600&display=swap" rel="stylesheet">
<?php
}
import csv
import requests
import json
def get_json():
url = "https://www.ozon.ru/api/composer-api.bx/page/json/v2" \
"?url=/product/avtomaticheskaya-kofemashina-inhouse-rozhkovaya-coffee-arte-icm1507-seryy-397529235/"
response = requests.get(url=url)
with open('ozon_1.json', 'w', encoding='utf-8') as file:
@DxDiagDx
DxDiagDx / functions.php
Last active April 22, 2022 09:46
Woo: Скрыть сайдбар в категориях первого уровня
/* Скрыть сайдбар в категориях первого уровня */
add_action( 'get_header', 'remove_storefront_sidebar' );
function remove_storefront_sidebar() {
if (is_product_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$category_parent = $cat_obj->parent;
if ( $category_parent == 0) {
remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
?>
@DxDiagDx
DxDiagDx / avito_phone.py
Last active August 24, 2022 09:56
AVITO - парсинг номера телефона
import urllib.parse
import requests
def get_phone(offer_id):
"""offer_id - ID объявления"""
params = (
('key', 'af0deccbgcgidddjgnvljitntccdduijhdinfgjgfjir'),
)
@DxDiagDx
DxDiagDx / functions.php
Created March 24, 2022 10:27
WooCommerce - скрыть количество товаров в категориях
add_filter( 'woocommerce_subcategory_count_html', 'woo_remove_category_products_count' );
function woo_remove_category_products_count() {
return;
}
@DxDiagDx
DxDiagDx / get_images.py
Last active April 5, 2023 04:38
Python: скачать и переименовать изображения для интернет-магазина
import csv
from pathlib import Path
import requests
from transliterate import slugify
def download_image(image_url, image_name):
# получаем расширение файла изображения из url
# и добавлем его к имени изображения
image_name += Path(image_url).suffix
@DxDiagDx
DxDiagDx / telegram.py
Created December 13, 2021 14:55
Python — отправить сообщение в telegram
import requests
def send_telegram(text: str):
token = 'token'
url = "https://api.telegram.org/bot"
channel_id = 'channel_id'
url += token
method = url + "/sendMessage"
@DxDiagDx
DxDiagDx / functions.php
Created December 6, 2021 13:53
Woo: Показать кнопки + - количество рядом с кнопкой добавления в корзину
/* Показать кнопки + - количество рядом с кнопкой добавления в корзину */
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false );
$html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
$html .= '</form>';
}
return $html;
@DxDiagDx
DxDiagDx / webscrapper.json
Created October 14, 2021 08:59
avito.ru - Webscrapper Sitemap
{"_id":"avito","startUrl":["https://www.avito.ru/krasnodar/kvartiry/sdam/na_dlitelnyy_srok/2-komnatnye-ASgBAQICAkSSA8gQ8AeQUgFAzAgUkFk?cd=1&p=[1-6]"],"selectors":[{"delay":0,"id":"adv","multiple":true,"parentSelectors":["_root"],"selector":"div.iva-item-list-H_dpX","type":"SelectorElement"},{"delay":0,"id":"link","multiple":false,"parentSelectors":["adv"],"selector":"a.link-link-MbQDP[itemprop='url']","type":"SelectorLink"},{"delay":0,"id":"price","multiple":false,"parentSelectors":["adv"],"regex":"","selector":"span.price-text-E1Y7h","type":"SelectorText"}]}
@DxDiagDx
DxDiagDx / functions.php
Last active October 5, 2021 14:37
Woo: вывести значения атрибута в коротком описании карточки товара
/*
* Вывод атрибутов в коротком описании
*/
add_action( 'woocommerce_single_product_summary', 'show_attr_singe_product', 21 );
function show_attr_singe_product() {
global $product;
// Получаем элементы таксономии атрибута color
$attribute_names = get_the_terms($product->get_id(), 'pa_color');
$attribute_name = "pa_color";
if ($attribute_names) {