/**
* Делаем ссылки вида: /%category%/%post_tag%/%postname%/ + настраиваем пагинацию
*/
function flush_rewrite_rules_on_activation() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'flush_rewrite_rules_on_activation' );
function custom_rewrite_tag() {
add_rewrite_tag('%tag%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
function custom_rewrite_rules() {
add_rewrite_rule('^(news||faq||actions)/page/([0-9]+)/?', 'index.php?category_name=$matches[1]&paged=$matches[2]', 'top');
add_rewrite_rule('^(news||faq||actions)/([^/]*)/page/([0-9]+)/?', 'index.php?category_name=$matches[1]&tag=$matches[2]&paged=$matches[3]', 'top');
add_rewrite_rule('^(news||faq||actions)/([^/]*)/([^/]*)/?', 'index.php?category_name=$matches[1]&tag=$matches[2]&name=$matches[3]', 'top');
}
add_action('init', 'custom_rewrite_rules');
function custom_query_vars($query_vars) {
$query_vars[] = 'tag';
return $query_vars;
}
add_filter('query_vars', 'custom_query_vars');
function custom_parse_request($query) {
if (!empty($query->query_vars['tag']) && !empty($query->query_vars['category_name'])) {
$post_tag = $query->query_vars['tag'];
$category = $query->query_vars['category_name'];
$term = get_term_by('slug', $post_tag, 'post_tag');
if (!$term && $post_tag !== 'page' && $post_tag !== 'all') {
global $wp_query;
$wp_query->set_404();
status_header(404);
get_template_part(404);
exit();
}
$args = array(
'category_name' => $category,
'tag' => $post_tag,
'post_type' => 'post',
'posts_per_page' => 1
);
$posts = get_posts($args);
if (empty($posts) && $post_tag !== 'page' && $post_tag !== 'all') {
global $wp_query;
$wp_query->set_404();
status_header(404);
get_template_part(404);
exit();
}
}
}
add_action('parse_request', 'custom_parse_request', 10, 1);
/**
* Редактируем ссылки на постах
*/
function custom_permalink_structure($permalink, $post, $leavename) {
if (strpos($permalink, '%tag%') === FALSE) return $permalink;
// Получаем теги поста
$tags = get_the_terms($post, 'post_tag');
if (!is_wp_error($tags) && !empty($tags) && is_object($tags[0])) {
$tag_slug = $tags[0]->slug;
} else {
$tag_slug = 'all';
}
$permalink = str_replace('%tag%', $tag_slug, $permalink);
return $permalink;
}
add_filter('post_link', 'custom_permalink_structure', 10, 3);
add_filter('post_type_link', 'custom_permalink_structure', 10, 3);
// Ajax обновление корзины
const ajaxUpdateCartContainer = document.querySelector('div.woocommerce');
if (ajaxUpdateCartContainer){
ajaxUpdateCartContainer.addEventListener('change', ({ target }) => {
target.closest('input.qty');
document.querySelector('[name="update_cart"]').click();
});
}
<section class="">
<div class="container">
<?php
$loop = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => 2+1,
'orderby' => 'menu_order',
'order' => 'ASC',
));
?>
<div class="woocommerce">
<ul class="products products_archive_grid">
<?
while ( $loop->have_posts() ): $loop->the_post();
$id = get_the_ID();
$short = do_shortcode('[product id="'.$id.'"]');
$short = str_replace(
"<div class=\"woocommerce \"><ul class=\"products products_archive_grid\">",
"",
$short);
$short = substr($short,0,-11);
echo $short;
endwhile;
?>
</ul>
</div>
</div>
</section>
function rstheme_acf_blocks()
{
if ( function_exists('acf_register_block_type') ) {
acf_register_block_type( array(
.
.
.
.
.
'mode' => 'edit'
) );
}
}
add_action('acf/init', 'rstheme_acf_blocks');
( function( blocks, element, blockEditor ) {
let el = element.createElement;
let InnerBlocks = blockEditor.InnerBlocks;
blocks.registerBlockType( 'gutenberg-custom-block/section', {
title: 'Section',
description: 'section description',
category: 'layout',
keywords: 'section',
icon: {
background: '#7e70af',
foreground: '#fff',
src: 'book-alt'
},
edit: function( props ) {
return el(
'section',
{ className: props.className},
el( InnerBlocks )
);
},
save: function( props ) {
return el(
'section',
{ className: props.className },
el( InnerBlocks.Content )
);
},
} );
} (
window.wp.blocks,
window.wp.element,
window.wp.blockEditor,
) );
<section class="wp-block-gutenberg-custom-block-section">
<!-- ТУТ ВЛОЖЕННЫЕ БЛОКИ -->
</section>
/*
* Добавляем к лиду комментарий
*/
$comment_timeline = <<<EOD
<b>Правила обработки заявки</b>
<ol>
<li>Позвонить, помочь зарегистрировать клиента</li>
<li>Перенести лид на 2 недели</li>
<li>Через 2 недели узнать как клиенту сервис</li>
<li>Связаться с клиентом за неделю до окончания ТД</li>
<li>ПРОДАТЬ ЭЛЬБУ</li>
</ol>
<b>P.S. номер тех.поддержки: 8 (800) 800 80 80</b>
EOD;
$queryUrl = 'https://xxxx.bitrix24.ru/rest/x/xxxxxxxxxxxxx/crm.timeline.comment.add.json';
$queryData = http_build_query(array(
'fields' => Array(
"ENTITY_ID" => $leadID,
"ENTITY_TYPE" => "lead",
"COMMENT" => $comment_timeline
),
));
$curl = curl_init();
$curl_array = [CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $queryUrl, CURLOPT_POSTFIELDS => $queryData];
curl_setopt_array($curl, $curl_array);
$result = curl_exec($curl);
curl_close($curl);
}
$array = $manager_and_product[$product_id];
$product_id = $array['product_id'];
$manager_id_array = $array['manager_id'];
foreach ($manager_id_array as $id){
$user_online = file_get_contents('https://XXXXX.bitrix24.ru/rest/ID/XXXXXXXXXXX/user.get.json?IS_ONLINE=Y&id='.$id);
$user_online = json_decode($user_online, true);
if(count($user_online['result'][0]) > 0){
$manager_id = $id;
}else{
$manager_id = $manager_id_array[0];
}
}