Skip to content

Instantly share code, notes, and snippets.

View artikus11's full-sized avatar
🥕
Create plugins

Artem Abramovich artikus11

🥕
Create plugins
View GitHub Profile
/*
* Пример использования
*/
$counts = [ 1, 2, 7 ];
foreach ( $counts as $count ) {
echo $count . ' - ' . get_num_ending( $count, [ 'машина', 'машины', 'машин' ] ) . '<br>';
}
/*
<?php
/**
* Collection Products
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/related.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
/**
* Вывод скидки по купону в подытогах каждого товара
*
* @param $product_subtotal
* @param $product
* @param $quantity
* @param $cart
*
* @return string
*/
add_filter(
'woocommerce_settings_pages',
function ( $setting ) {
unset( $setting[1]['args'] );
unset( $setting[2]['args'] );
return $setting;
}
);
@artikus11
artikus11 / added-function.php
Last active July 26, 2020 16:15
Массовое добавление картинок по атрибуту
add_action( 'woocommerce_variable_product_bulk_edit_actions', 'set_image_by_attributes', 10 );
function set_image_by_attributes() {
global $post, $woocommerce;
$attributes = maybe_unserialize( get_post_meta( $post->ID, '_product_attributes', true ) );
$out = "";
function recipe_time( $field_name = '', $field_desc = '', $iso = false ) {
$time = get_field( $field_name ) ? get_field( $field_name ) : 1;
$hours = floor( $time / 60 );
$minutes = ( $time % 60 ) <= 0 ? '' : $time % 60;
$hours_out = ( $hours ) ? $hours . ' ' . get_num_ending( $hours, array( 'час', 'часа', 'часов' ) ) . ' ' : '';
$minutes_out = ( $minutes ) ? $minutes . ' мин' : '';
$hours_iso = ( $hours ) ? $hours . 'H' : '';
$minutes_iso = ( $minutes ) ? $minutes . 'M' : '';
function preload_fonts() {
$preload = "<link rel='preconnect' href='https://fonts.gstatic.com' crossorigin />\n";
$preload .= sprintf(
'<link rel="preload" as="style" href="%1$s" />%2$s',
$this->get_add_query_arg( $this->font_args, $this->font_url ),
"\n"
);
<?php
class CNWS_Schema {
public function __construct() {
$this->hooks();
}
@artikus11
artikus11 / added-function.php
Last active January 11, 2022 08:59
Создание записи при отправке формы из Contact Form 7
add_action( 'wpcf7_before_send_mail', 'created_post_in_cf7' );
function created_post_in_cf7( $contact_form ) {
$title = $_POST['text-title-post'] && ! empty( $_POST['text-title-post'] ) ? sanitize_text_field( $_POST['text-title-post'] ) : '';
$content = $_POST['text-contant-post'] && ! empty( $_POST['text-contant-post'] ) ? wp_strip_all_tags( $_POST['text-contant-post'] ) : '';
$field = $_POST['text-field-post'] && ! empty( $_POST['text-field-post'] ) ? sanitize_text_field( $_POST['text-field-post'] ) : '';
$ars = [
'post_type' => 'post',
'post_title' => $title,
@artikus11
artikus11 / passing-variables-to-get_template_part-in-wordpress.php
Created October 22, 2019 18:46 — forked from mihdan/passing-variables-to-get_template_part-in-wordpress.php
Передача переменных для get_template_part()
<?php
/**
* Load a template part into a template
*
* @param string $slug The slug name for the generic template.
* @param string $name The name of the specialised template.
* @param array $params Any extra params to be passed to the template part.
*/
function get_template_part_extended( $slug, $name = null, $params = array() ) {
if ( ! empty( $params ) ) {