Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-statistics domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the cyr2lat domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the essential-addons-for-elementor-lite domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the translatepress-multilingual domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 Полезные сниппеты Wordpress - WP-prog

WP-prog

Полезные сниппеты WordPress

1. Удалить опции сортировки со страницы каталога

				
					remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );

				
			

2. Сортировка товаров в каталоге по произвольному полю ACF

				
					add_action( 'woocommerce_get_catalog_ordering_args', 'esa_sort_by_date' );
function esa_sort_by_date($args){
		$args['order'] = 'ASC';
		$args['meta_key'] = 'acf_date_edu';
		$args['orderby'] = 'meta_value';
return $args;
}
				
			

3. После добавления товара в корзину переходим сразу на страницу заказа

				
					add_filter('woocommerce_add_to_cart_redirect', 'esa_skip_cart');
function esa_skip_cart($redirect)
{
	return wc_get_checkout_url();
}
				
			

4. Убрать последний пункт из хлебных крошек товара Woocommerce

Скопируем файл из плагина woocommerce/global/breadcrumb.php в свою тему и напишем обертку для echo esc_html( $crumb[0] ); , затем спрячем его через CSS

				
					if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! empty( $breadcrumb ) ) {

	echo $wrap_before;

	foreach ( $breadcrumb as $key => $crumb ) {

		echo $before;

		if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
			echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
		} else {
			echo '<span id="esa-breadcrumb-last" style="display:none;">';
            echo esc_html( $crumb[0] );
            echo '</span>';
// 			echo esc_html( $crumb[0] );
		}

		echo $after;

		if ( sizeof( $breadcrumb ) !== $key + 1 ) {
			echo $delimiter;
		}
	}

	echo $wrap_after;

}

				
			

5. Отключаем Гутенберг для виджетов

				
					add_filter('gutenberg_use_widgets_block_editor', '__return_false', 100);
add_filter('use_widgets_block_editor', '__return_false');
				
			

6. Сортировка товаров на странице магазина по наименованию в обратном порядке

				
					add_action( 'woocommerce_product_query', 'product_query_sort_alphabetically' );
function product_query_sort_alphabetically( $q ) {
    if ( ! isset( $_GET['orderby'] ) && ! is_admin() ) {
        $q->set( 'orderby', 'title' );
        $q->set( 'order', 'DESC' );
    }
}
				
			

7. ID текущей страницы атрибута для поля ACF:

				
					$desc_tags = get_field('desc_attrib', 'term_' . term_exists(single_term_title('', false)));

				
			

8. ID текущей категории для поля ACF:

				
					$des_category = get_field('des_category', 'term_' . get_queried_object()->term_id);