Tips / Recommendations

How to Hide Posts or Pages from the WordPress Admin

Posted on

function true_hide_pages_from_admin( $query ) { global $pagenow; if( is_admin() && ‘edit.php’ == $pagenow && ‘page’ == get_query_var(‘post_type’) ){ // в качестве ‘page’ в условии можно указать любой произвольный тип постов $query->set( ‘post__not_in’, array(300,271) ); // через запятую прописываем ID страниц, которые хотим скрыть } return $query; } add_action( ‘pre_get_posts’ ,’true_hide_pages_from_admin’ ); function true_hide_posts_from_admin( $query ) […]

Tips / Recommendations

Change photo in url

Posted on

<meta name="viewport" content="width=device-width, initial-scale=1"> <meta property="og:image" content="https://onmywaystudio.net/wp-content/uploads/2018/05/cropped-download-1-1.png;" /> <meta property="og:image:secure_url" content="https://onmywaystudio.net/wp-content/uploads/2018/05/cropped-download-1-1.png"; /> <meta property="og:image:type" content="image/jpeg" /> <meta property="og:image:width" content="400" /> <meta property="og:image:height" content="300" /> <meta property="og:image:alt" content="" />

Tips / Recommendations

Adding consent to the WooCommerce Privacy Policy

Posted on

// Добавление чекбокса add_action( ‘woocommerce_review_order_before_submit’, ‘truemisha_privacy_checkbox’, 25 ); function truemisha_privacy_checkbox() { woocommerce_form_field( ‘privacy_policy_checkbox’, array( ‘type’ => ‘checkbox’, ‘class’ => array( ‘form-row’ ), ‘label_class’ => array( ‘woocommerce-form__label-for-checkbox’ ), ‘input_class’ => array( ‘woocommerce-form__input-checkbox’ ), ‘required’ => true, ‘label’ => ‘Принимаю <a href=”‘ . get_privacy_policy_url() . ‘”>Политику конфиденциальности</a>’, )); } // Валидация add_action( ‘woocommerce_checkout_process’, ‘truemisha_privacy_checkbox_error’, 25 ); function […]

Tips / Recommendations

Product availability in Woocommerce

Posted on

add_action( ‘woocommerce_before_shop_loop_item_title’, ‘my_sold_out_loop’ ); function my_sold_out_loop() { global $product; if ( !$product->is_in_stock() ) { echo ‘<span class=”soldout”>Нет в наличии</span>’; } } add_action( ‘woocommerce_before_single_product_summary’, ‘my_sold_out_loop’ ); span.soldout { padding: 3px 7px; background: #7b1616; color: white; font-size: 13px; } add_filter( ‘woocommerce_get_availability’, ‘wcs_custom_get_availability’, 1, 2); function wcs_custom_get_availability( $availability, $_product ) { if ( $_product->is_in_stock() ) { $availability[‘availability’] = […]

Tips / Recommendations

Add field to user profile wordpress and woocommerce

Posted on

function my_user_contactmethods($user_contactmethods){ $user_contactmethods[‘phone’] = ‘Телефон’; return $user_contactmethods; } add_filter(‘user_contactmethods’, ‘my_user_contactmethods’); <p class=”form-row form-row-wide”> <label for=”phone”>Phone</label> <input type=”text” class=”input-text” name=”phone” id=”phone” value=”<?php echo esc_attr( $user->phone ); ?>” /> </p> $phone = ! empty( $_POST[ ‘phone’ ] ) ? $_POST[ ‘phone’ ] : ”; $user->phone = $phone;

Tips / Recommendations

Woocommerce product category description under products

Posted on

In order to display the description of the Woocommerce product category at the bottom of the page – under the products, you need to add the following code to the functions.php file of the theme: remove_action( ‘woocommerce_archive_description’, ‘woocommerce_taxonomy_archive_description’, 10 ); add_action( ‘woocommerce_after_shop_loop’, ‘woocommerce_taxonomy_archive_description’, 100 ); function woocommerce_taxonomy_archive_description() { if ( is_tax( array( ‘product_cat’, ‘product_tag’ ) […]

Tips / Recommendations

Sorting WordPress posts by creation time and AFC custom field

Posted on

add_action(‘pre_get_posts’, ‘my_pre_get_posts’, 10, 1); function my_pre_get_posts($query) { if ($query->is_main_query() && !is_admin()) { $query->set(‘meta_key’, ‘sorting’); // сортировка по произвольному полю $query->set(‘orderby’, ‘meta_value_num’); $query->set(‘order’, ‘ASC’); // порядок сортировки } $query->set(‘meta_query’, $meta_query); } function postSorting() { $todays_date = current_time(‘Ymd’); $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => ‘4’, ‘paged’ => $paged, ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘sorting_clause’ […]

Tips / Recommendations

Percentage Discount on Whole Cart Without Coupon in WooCommerce

Posted on

Fixed Percentage Discount on Whole Cart in WooCommerce So, let’s start with the simplest discount – fixed. In it, the discount will be applied to the entire basket as a result, without unnecessary actions on the part of the user. Discount script: function woo_discount_total(WC_Cart $cart) { if(is_admin() && !defined(‘DOING_AJAX’)) { return; } $discount = $cart->subtotal […]

Tips / Recommendations

Enable phone field validation in woocommerce

Posted on

// Custom validation for Billing Phone checkout field add_action(‘woocommerce_checkout_process’, ‘custom_validate_billing_phone’); function custom_validate_billing_phone() { $is_correct = preg_match(‘^((8|+7)[- ]?)?((?d{3})?[- ]?)?[d- ]{7,10}$’, $_POST[‘billing_phone’]); if ($_POST[‘billing_phone’] && !$is_correct) { wc_add_notice(__(‘The Phone field should be <strong>between 6 and 20 digits</strong>.’), ‘error’); } }