Skip to content

Instantly share code, notes, and snippets.

Avatar

Evgeny Lukin DxDiagDx

View GitHub Profile
@DxDiagDx
DxDiagDx / functions.php
Last active Jul 26, 2021
Woo: Custom text on checkout page / Свой текст на странице оформления заказа
View functions.php
/**
* Текст на странице оформления заказа
*/
add_filter('woocommerce_thankyou_order_received_text', 'woo_my_thankyou_order_received_text' );
function woo_my_thankyou_order_received_text() {
return 'Спасибо. Ваш заказ был принят.</br>В ближайшее время с вами свяжется менеджер для подтверждения.';
}
@DxDiagDx
DxDiagDx / functions.php
Created Jul 21, 2021
Woo: вывести в карточке товара ссылки на другие товары (через апсейл)
View functions.php
/* Карточка товара */
// Короткое описание
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
function woocommerce_template_single_excerpt() {
global $product;
$upsale_products = $product->get_upsell_ids();
if ( !empty($upsale_products) ) {
@DxDiagDx
DxDiagDx / functions.php
Created May 19, 2021
WooCommerce: добавить вкладку со ссылкой на страницу
View functions.php
/**
* Добавляем вкладку «Оплата и доставка» в карточке товара (фронтенд)
*/
add_filter('woocommerce_product_tabs','add_tabs');
function add_tabs($tabs){
$tabs[ 'payment_delivery' ] = array(
'title' => 'Оплата и доставка',
@DxDiagDx
DxDiagDx / app.py
Created May 3, 2021
WordPress + Python: удалить пост
View app.py
import requests
import base64
url = "https://wholeblogs.com/wp-json/wp/v2/posts/"
postID = '1'
user = "your-username"
password = "your-application-password"
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
@DxDiagDx
DxDiagDx / app.py
Last active May 3, 2021
WordPress + Python: редактировать пост
View app.py
import requests
import base64
url = "https://wholeblogs.com/wp-json/wp/v2/posts/"
postID = '1'
user = "your-username"
password = "your-application-password"
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
@DxDiagDx
DxDiagDx / app.py
Created May 3, 2021
WordPress + Python: создать пост
View app.py
import requests
import base64
url = "https://wholeblogs.com/wp-json/wp/v2/posts"
user = "your-username"
password = "your-application-password"
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header = {'Authorization': 'Basic ' + token.decode('utf-8')}
post = {
@DxDiagDx
DxDiagDx / python-test.py
Last active May 3, 2021
WordPress + Python: авторизация
View python-test.py
import requests
import json
import base64
url = "https://example.com/wp-json/wp/v2/posts"
user = "your-username"
password = "your-application-password"
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header = {'Authorization': 'Basic ' + token.decode('utf-8')}
@DxDiagDx
DxDiagDx / functions.php
Created Apr 27, 2021
Woo Import: добавить произвольное поле в стандартный импорт
View functions.php
/**
* Register the 'Custom Column' column in the importer.
*
* @param array $options
* @return array $options
*/
add_filter( 'woocommerce_csv_product_import_mapping_options', 'add_column_to_importer' );
function add_column_to_importer( $options ) {
// column slug => column name
$options['_price_types_1'] = 'Оптовая цена'; return $options;
@DxDiagDx
DxDiagDx / functions.php
Last active Apr 2, 2021
Woo: убираем не нужный / лишний тег H2 на страницах категорий
View functions.php
// Заменяем тег <H2> на <H3> у подкатегорий
remove_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title', 10 );
add_action( 'woocommerce_shop_loop_subcategory_title', 'custom_woocommerce_template_loop_category_title', 10 );
function custom_woocommerce_template_loop_category_title( $category ) {
echo '<h3 class="woocommerce-loop-category__title">';
echo esc_html( $category->name );
if ( $category->count > 0 ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo apply_filters( 'woocommerce_subcategory_count_html', ' <mark class="count">(' . esc_html( $category->count ) . ')</mark>', $category );
}
@DxDiagDx
DxDiagDx / functions.php
Created Apr 1, 2021
Woo: cкрыть категорию Uncategorized со страницы магазина
View functions.php
// Скрыть категорию Uncategorized со страницы магазина
add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 );
function ts_get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() &&is_shop() ) {
foreach( $terms as $key => $term ) {
if ( !in_array( $term->slug, array( 'uncategorized' ) ) ) { //ваш слаг категории
$new_terms[] = $term;
}
}