• Skip to main content
  • Skip to primary sidebar

WordPress, Genesis Framework and Storefront customization tutorials

  • Archive
    • Free
    • Premium
  • Blog
  • About
  • Contact
  • Newsletter
  • Login
Home » Premium » Page 2

Premium

Hide header when scrolling down, show it when scrolling up in Genesis

JavaScript

// =========================================================================
// SMART HEADER
// =========================================================================
add_action('wp_footer','header_sticky_script');
function header_sticky_script()
{
?>
	<script>	
		// Hide Header on Scroll Down but Show when Scroll Up
		var didScroll;
		var lastScrollTop = 0;
		var delta = 5;
		var navbarHeight = '';

		jQuery(window).load( function() {
			navbarHeight = jQuery('header.site-header').outerHeight();
			jQuery('body').css('paddingTop',navbarHeight);
		});

		jQuery(window).scroll(function(event){
			didScroll = true;
		});

		setInterval(function() {
			if (didScroll) {
				ghasScrolled();
				didScroll = false;
			}
		}, 250);

		function hasScrolled() 
		{
			var st = jQuery(this).scrollTop();
			
			// Make sure to scroll more than delta
			if(Math.abs(lastScrollTop - st) <= delta)
				return;
			
			// If scrolled down and are past the navbar
			// This is necessary so you never see what is "behind" the navbar.
			if (st > lastScrollTop && st > navbarHeight){
				// Scroll Down
				jQuery('header.site-header').css('top',-navbarHeight).removeClass('shadow');
			} else {
				// Scroll Up
				if(st + jQuery(window).height() < jQuery(document).height()) {
					jQuery('header.site-header').css('top',0).addClass('shadow');
				}
			}
			
			if (st < 15){
				jQuery('header.site-header').css('top',0).removeClass('shadow');
			}
			
			lastScrollTop = st;
		}
	</script>	
<?php
}

CSS

/* Smart Header */


header.site-header {
        position: fixed;
        top: 0;
        transition: top 0.3s ease-in-out;
        width: 100%;
        z-index: 9;
        left: 0;
        right: 0;
}


header.site-header.shadow {
        -webkit-box-shadow: 0 0 50px rgba(0,0,0,.15);
        box-shadow: 0 0 50px rgba(0,0,0,.15);
}

body.admin-bar header.site-header{
        top: 32px;
}

@media only screen and (max-width: 780px) 
{
        body.admin-bar header.site-header{
                top: 46px;
        }

}

Filed Under: Premium Tagged With: JavaScript

Disable payment method for specific country in WooCommerce

// =========================================================================
// DISABLE COD PAYMENT METHOD FOR SPECIFIC COUNTRY - DE
// =========================================================================
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country_de' );
  
function payment_gateway_disable_country_de( $available_gateways ) {
    if ( is_admin() ) return;
    if ( isset( $available_gateways['authorize'] ) && WC()->customer->get_billing_country() <> 'DE' ) {
        unset( $available_gateways['authorize'] );
    } else {
        if ( isset( $available_gateways['cod'] ) && WC()->customer->get_billing_country() == 'DE' ) {
            unset( $available_gateways['cod'] );
        }
    }
    return $available_gateways;
}

Filed Under: Premium Tagged With: WooCommerce

Add fee to specific payment gateway only for physical products

// =========================================================================
// ADD FEE TO SPECIFIC PAYMENT GATEWAY => COD - ONLY FOR PHYSICAL PRODUCT
// =========================================================================
// Part 1: assign fee
 
add_action( 'woocommerce_cart_calculate_fees', 'add_checkout_fee_for_gateway' );
 
function add_checkout_fee_for_gateway() {
    
     
    foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
        // Check if there are non-virtual products
        if ( ! $cart_item['data']->is_virtual() ) {
            $chosen_gateway = WC()->session->chosen_payment_method;
  
              if ( $chosen_gateway == 'cod' ) {

              // Note: edit "Fee" and "5" below to control Label and Fee Amount
              WC()->cart->add_fee( __('Utánvét díja', 'woocommerce'), 510 );

              }
        }
    }
 
}
 
// Part 2: reload checkout on payment gateway change
 
add_action( 'woocommerce_review_order_before_payment', 'refresh_checkout_on_payment_methods_change' );
 
function refresh_checkout_on_payment_methods_change(){
    ?>
    <script type="text/javascript">
        (function($){
            $( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
                $('body').trigger('update_checkout');
            });
        })(jQuery);
    </script>
    <?php
}

Filed Under: Premium Tagged With: WooCommerce

Add custom out of stock message for specific product category

// =========================================================================
// ADD CUSTOM MESSAGE IF SPECIFIC PRODUCT CATEGORY OUT OF STOCK
// =========================================================================
add_filter( 'woocommerce_get_availability', 'woo_custom_get_availability', 1, 2);
function woo_custom_get_availability( $availability, $_product ) {
    
    global $product;
    //CATEGORY 1
    if ( has_term( 'CATEGORY_NAME_1', 'product_cat', $product->get_id() ) ) {
        // Change In Stock Text
        if ( $_product->is_in_stock() ) {
            $availability['availability'] = __('Available!', 'woocommerce');
        }
        // Change Out of Stock Text
        if ( ! $_product->is_in_stock() ) {
            $availability['availability'] = __('Jelenleg nincs kitűzve tréning időpont', 'woocommerce');
        }
        return $availability;
    }
    //CATEGORY 2
    else if ( has_term( 'CATEGORY_NAME_2', 'product_cat', $product->get_id() ) ) {
        // Change In Stock Text
        if ( $_product->is_in_stock() ) {
            $availability['availability'] = __('Available!', 'woocommerce');
        }
        // Change Out of Stock Text
        if ( ! $_product->is_in_stock() ) {
            $availability['availability'] = __('Jelenleg nincs kitűzve tréning időpont', 'woocommerce');
        }
        return $availability;
    }
    else{
        // Change In Stock Text
        if ( $_product->is_in_stock() ) {
            $availability['availability'] = __('Készleten', 'woocommerce');
        }
        // Change Out of Stock Text
        if ( ! $_product->is_in_stock() ) {
            $availability['availability'] = __('Elfogyott', 'woocommerce');
        }
        return $availability;
    }
}

Filed Under: Premium Tagged With: WooCommerce

Hide specific Flat Rates when Free Shipping is available

//Hide specific Flat Rates when Free Shipping is available
add_filter( 'woocommerce_package_rates', 'conditionally_hide_shipping_methods', 100, 2 );
function conditionally_hide_shipping_methods( $rates, $package ) {
    // HERE yours 2nd flat rate "Express Shipping" (that you never hide) in the array:
    $flat_rates_pickpack = array( 
        'wc_pont_shipping_method:3', 
        'local_pickup:9' 
    );

    $free = $flat2 = array();
    foreach ( $rates as $rate_key => $rate ) {
        // Updated Here To 
        if ( in_array( $rate->id, $flat_rates_pickpack ) ) 
            $flat2[ $rate_key ] = $rate;
        if ( 'free_shipping' === $rate->method_id )
            $free[ $rate_key ] = $rate;
    }
    return ! empty( $free ) ? array_merge( $free, $flat2 ) : $rates;
}

Filed Under: Premium Tagged With: Storefront

WooCommerce free shipping over amount and hide other shipping methods

https://flexibleshipping.com/woocommerce-free-shipping-over-amount/

Filed Under: Premium Tagged With: WooCommerce

Move Header Cart and Product Search before header in Storefront

// =========================================================================
//CHANGE DEFAULT STOREFRONT HEADER LAYOUT 
// =========================================================================
function remove_storefront_actions() {
	remove_action( 'storefront_header', 'storefront_product_search', 40 );
    remove_action( 'storefront_header', 'storefront_primary_navigation', 50 );
    remove_action( 'storefront_header', 'storefront_header_cart', 60 );
}
add_action( 'init', 'remove_storefront_actions' );

function add_top_bar_opening_wrap(){
    echo '<div class="top-bar">';
}
function add_top_bar_closing_wrap(){
    echo '</div>';
}

add_action( 'storefront_before_header', 'add_top_bar_opening_wrap', 1 );
add_action( 'storefront_before_header', 'storefront_header_cart', 2 );
add_action( 'storefront_before_header', 'storefront_product_search', 40 );
add_action( 'storefront_before_header', 'add_top_bar_closing_wrap', 50 );

Filed Under: Premium Tagged With: Storefront

How to add Page Title Background with ACF

Step 1

Install and activate Advanced Custom Fields

Step 2

Go to Custom Fields

Add a header_background field group in your site.

Step 3

// Adds custom image size for site header background image.
add_image_size( 'header-image', 1600, 350, true );

add_action( 'wp_enqueue_scripts', 'custom_header_background' );
/**
 * Sets `header_background` as URL of .site-header.
 */
function custom_header_background() {

    // if we are not on a static Page, abort.
    if ( ! is_singular( 'page' ) ) {
        return;
    }

    // get the custom field's ID.
    $image = get_field( 'header_background' );

    // URL of image custom field in a specific size.
    $url = wp_get_attachment_image_url( $image, 'header-image' );

    if ( ! empty( $image ) ) {
        $css = '
        .site-header {
            background-image: url( ' . $url . ' ) !important;
        }';

        wp_add_inline_style( 'anchored', $css );
    }

}

Filed Under: Premium Tagged With: ACF

Disable Payment Gateway For Specific Product Category

//DISABLE COD PAYMENT FOR SPECIFIC PRODUCT CATEGORY
function unset_payment_cod_for_online_trening( $available_gateways ) {
    global $woocommerce;
    $unset = false;
    $category_ids = array( 109 );
    foreach ( $woocommerce->cart->cart_contents as $key => $values ) {
        $terms = get_the_terms( $values['product_id'], 'product_cat' );    
        foreach ( $terms as $term ) {        
            if ( in_array( $term->term_id, $category_ids ) ) {
                $unset = true;
                break;
            }
        }
    }
        if ( $unset == true ) unset( $available_gateways['cod'] );
        return $available_gateways;
}
add_action( 'woocommerce_available_payment_gateways', 'unset_payment_cod_for_online_trening', 5 );

Filed Under: Premium Tagged With: WooCommerce

Disable Payment Gateway For Specific Shipping Method

<?php
//Disable Payment Gateway For Specific Shipping Method

add_filter( 'woocommerce_available_payment_gateways', 'wpflames_gateway_disable_shipping_368' );

function wpflames_gateway_disable_shipping_368( $available_gateways ) {

    global $woocommerce;

    if ( !is_admin() ) {

        $chosen_methods = WC()-&amp;gt;session-&amp;gt;get( 'chosen_shipping_methods' );

        $chosen_shipping = $chosen_methods[0];

        //Free shipping
        if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'free_shipping' ) ) {
            unset( $available_gateways['cod'] );
        }

        //Flat rate
        if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'flat_rate' ) ) {
            unset( $available_gateways['cheque'] );
        }
        //Local pickup
        if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
            unset( $available_gateways['cod'] );
        }
        
        //Cheque
        if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'flat_rate:2' ) ) {
            unset( $available_gateways['cheque'] );
        }

    }

return $available_gateways;

}

Filed Under: Premium Tagged With: WooCommerce

How to send custom email based on product ID in WooCommerce

add_action( 'woocommerce_email_before_order_table', 'add_online_trening_welcome_email_text', 10, 2 );

function add_online_trening_welcome_email_text( $order, $sent_to_admin ) {

    if ( ! $sent_to_admin ) {

        foreach( $order->get_items() as $item ) {
            $product = wc_get_product( $item['product_id'] );

            // Use the name or product ID here
            if( $product->get_id() == 2767  ) {
                echo '<p style="text-align: center">A befizetést követően 1 munkanapon belül e-mailben megkapod a leírást, hogyan tudod elérni az online videókat. A számlád postán érkezik. Köszönöm, hogy a módszeremet választottad. Köszönöm, hogy tenni akarsz magadért.</p>';
            }
        }
    }
}

Filed Under: Premium Tagged With: WooCommerce

How to apply coupon when specific product ID in the cart?

//APPLY COUPON AUTOMATICALLY IF PRODUCT ID IS IN THE CART
add_action( 'woocommerce_before_cart', 'wpninja_apply_matched_coupons' );
 
function wpninja_apply_matched_coupons() {
 
    $coupon_code = 'sapikupon'; 
 
    if ( WC()->cart->has_discount( $coupon_code ) ) return;
 
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
 
        // this is your product ID
        $autocoupon = array( 1035 );

        if( in_array( $cart_item['product_id'], $autocoupon ) ) {   
            WC()->cart->add_discount( $coupon_code );
            wc_print_notices();
        }
    
    }
 
}

Filed Under: Premium Tagged With: WooCommerce

Custom Post Type Taxonomy Filter in Admin

<?php

add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
function tsm_filter_post_type_by_taxonomy() {
	global $typenow;
	$post_type = 'YOUR-POST-TYPE'; // change to your post type
	$taxonomy  = 'YOUR-TAXONOMY'; // change to your taxonomy
	if ($typenow == $post_type) {
		$selected      = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
		$info_taxonomy = get_taxonomy($taxonomy);
		wp_dropdown_categories(array(
			'show_option_all' => __("Összes kategória"),
			'taxonomy'        => $taxonomy,
			'name'            => $taxonomy,
			'orderby'         => 'name',
			'selected'        => $selected,
			'show_count'      => true,
			'hide_empty'      => true,
		));
	};
}

add_filter('parse_query', 'tsm_convert_id_to_term_in_query');
function tsm_convert_id_to_term_in_query($query) {
	global $pagenow;
	$post_type = 'YOUR-POST-TYPE'; // change to your post type
	$taxonomy  = 'YOUR-TAXONOMY'; // change to your taxonomy
	$q_vars    = &$query->query_vars;
	if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
		$term = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
		$q_vars[$taxonomy] = $term->slug;
	}
}

Filed Under: Premium Tagged With: PHP

How to create Bootstrap Accordion from Custom Post Type

Filed Under: Premium Tagged With: Bootstrap

How to set Featured Image as Background Cover with Title and Sub Title

Create a hook in functions.php

//ADD COVER TO ONLY SUB PAGES
function add_background_cover(){
    if ( !is_front_page() ) {
        include('inc/cover.php');
    }
}
add_action('genesis_after_header', 'add_background_cover');

Create a file inc/cover.php and place the following snippet in it. Don’t forget to replace the ACF slug in cover_subtitle() function!

<?php

//Cover Background
function cover_background() { 
    
    function cover_subtitle() { 
    if( get_field('........') ){ the_field('........') }
            else{ echo 'Hello World!'; }
        }
    
    $bgImage = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); 
    if( has_post_thumbnail() ){ ?>
            <section class="cover" style="background-image: url('<?php echo $bgImage[0]; ?>'); ">
                <h1 class="entry-title" itemprop="headline"><?php the_title(); ?></h1>
                <p><?php cover_subtitle(); ?></p>
            </section>
        <?php }
        else{  ?>
            <section class="cover" style="background-image: url(..............); ">
               <h1 class="entry-title" itemprop="headline"><?php the_title(); ?></h1>
                <p><?php cover_subtitle(); ?></p>
            </section>
            <?php
             }
    }
cover_background();
?> 

CSS

 .cover {
	height: 280px;
	padding-top: 60px;
}

Filed Under: Premium Tagged With: Genesis

How to add page title background cover to sub pages in Genesis

// =========================================================================
// ADD PAGE TITLE WITH BACKGROUND - ONLY SUB PAGES
// =========================================================================
function add_page_title_background(){
    if ( !is_front_page() ) {
        include('inc/page-title.php');
    }
}
add_action('genesis_after_header', 'add_page_title_background');

Filed Under: Premium Tagged With: Genesis

How to add Taxonomy Filter to WooCommerce admin

add_filter( 'woocommerce_product_filters', 'wpninja_filter_by_custom_taxonomy_dashboard_products' );
 
function wpninja_filter_by_custom_taxonomy_dashboard_products( $output ) {
   
  global $wp_query;
 
  $output .= wc_product_dropdown_categories( array(
    'show_option_none' => 'Filter by product tag',
    'taxonomy' => 'product_tag',
    'name' => 'product_tag',
    'selected' => isset( $wp_query->query_vars['product_tag'] ) ? $wp_query->query_vars['product_tag'] : '',
  ) );
   
  return $output;
}

Filed Under: Premium Tagged With: WooCommerce

Bootstrap Slider with Custom Post Type


<div id="slider-wrapper" class="container-fluid">

<div id="mySlider" class="carousel slide" data-ride="carousel"> 
  
   <ol class="carousel-indicators">
    <li data-target="#mySlider" data-slide-to="0" class="active"></li>
    <li data-target="#mySlider" data-slide-to="1"></li>
    <li data-target="#mySlider" data-slide-to="2"></li>
    <li data-target="#mySlider" data-slide-to="3"></li>
  </ol>
   
    <div class="carousel-inner" role="listbox">

      <!--LOOP ACTIVE ITEMS-->      
   
    <?php wp_reset_postdata();

	 $the_query = new WP_Query(array(
                'post_type' => 'slider', 
                'posts_per_page' => 1 
                )); 

                               
    while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
       <div class="carousel-item active">
       <img src="<?php the_field('slide'); ?>" alt="<?php the_field('caption_title'); ?>">
       <div class="carousel-caption">
           <h2><?php the_title(); ?></h2>
           <p class="hidden"><?php the_field('caption_text'); ?></p>
       </div>
        
    </div><!--item-active-->
    <?php endwhile; wp_reset_postdata(); ?>
    
<!--LOOP ITEMS-->    
      <?php  
       $the_query = new WP_Query(array(
                'post_type' => 'slider', 
                'posts_per_page' => 2, 
                'offset' => 1 
                )); 

                               
    while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
       <div class="carousel-item">
       <img src="<?php the_field('slide'); ?>" alt="<?php the_field('caption_title'); ?>">
       <div class="carousel-caption">
           <h2><?php the_title(); ?></h2>
           <p class="hidden"><?php the_field('caption_text'); ?></p>
       </div>
    </div><!--item-active-->
    <?php endwhile; wp_reset_postdata(); ?>
         
       </div>  
 
   <div class="carousel-control-wrapper hidden">
   <a class="carousel-control-prev" data-target="#mySlider" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="carousel-control-next" data-target="#mySlider" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>
</div>  
</div>

Filed Under: Premium Tagged With: Bootstrap

Loop Popular Posts

Add this snippet to functions.php

function shapeSpace_popular_posts($post_id) {
	$count_key = 'popular_posts';
	$count = get_post_meta($post_id, $count_key, true);
	if ($count == '') {
		$count = 0;
		delete_post_meta($post_id, $count_key);
		add_post_meta($post_id, $count_key, '0');
	} else {
		$count++;
		update_post_meta($post_id, $count_key, $count);
	}
}
function shapeSpace_track_posts($post_id) {
	if (!is_single()) return;
	if (empty($post_id)) {
		global $post;
		$post_id = $post->ID;
	}
	shapeSpace_popular_posts($post_id);
}
add_action('wp_head', 'shapeSpace_track_posts');

Displaying Popular Posts


<h3>Legnépszerűbb bejegyzések</h3>
<?php 
$args = array(
        'posts_per_page'=>3, 
        'meta_key'=>'popular_posts', 
        'orderby'=>'meta_value_num', 
        'order'=>'DESC'
);

$popular = new WP_Query( $args ); ?>

<div class="popular-posts">
<?php 	while ($popular->have_posts()) : $popular->the_post(); ?>
	<div class="row">
        <div class="col-md-4">
            <?php the_post_thumbnail( 'full', array('class' => 'img-responsive ') ); ?>
        </div>
        <div class="col-md-8">
            <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
            <time class="entry-date"><?php the_date('Y-m-d'); ?></time>
        </div>
    </div>
<?php endwhile; wp_reset_postdata(); ?>
</div>

Filed Under: Premium Tagged With: PHP

Loop Zillow CPT

<?php
$the_query = new WP_Query( $args );
?>
 
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<div class="review-content">
    

    
     <?php include('stars-main.php'); ?>
         <label class="highly">
             <?php if( get_field('main_review') == '5') : ?>
                 Highly likely to recommend
             <?php endif; ?>
             <?php if( get_field('main_review') == '4') : ?>
                 Likely to recommend
             <?php endif; ?>
             <?php if( get_field('main_review') == '3') : ?>
                 Might recommend
             <?php endif; ?>
         </label> <br>
     <ul class="review-metadata">
         <li><?php the_title(); ?></li>
         <li><?php the_field('short_description'); ?></li>
         <li>
                <?php if( get_field('primary_point_of_contact') ): ?>
                    <li><?php the_field('primary_point_of_contact'); ?></li>
                <?php endif; ?>
         </li>
     </ul>
     <div class="reviews-sub-ratings">
         <ul class="ratings">
             <li><span class="ratings-col">Local knowledge:</span> <?php include('stars-local.php'); ?></li>
             <li><span class="ratings-col">Process expertise:</span> <?php include('stars-process.php'); ?></li>
             <li><span class="ratings-col">Responsiveness:</span> <?php include('stars-respo.php'); ?></li>
             <li><span class="ratings-col">Negotiation skills:</span> <?php include('stars-nego.php'); ?></li>
         </ul>
     </div>
     <div class="review-body">
         <?php the_field('review'); ?>
     </div>
    
</div>

<?php
    endwhile;
else:
    echo 'No reviews yet.';
endif;
?>
 
<?php wp_reset_postdata(); ?>

Filed Under: Premium Tagged With: CPT

  • « Go to Previous Page
  • Page 1
  • Page 2
  • Page 3
  • Go to Next Page »

Primary Sidebar

Gabor Flamich

Hi! I'm Gabor.
I write tutorials on WordPress and WooCommerce.

MacBook

12 Essential Snippets for Genesis Developers

Subscribe to my Newsletter to view my basic collection of Genesis snippets that I use for my projects!

Sign Up for Free
  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
UpdraftPlus Premium

Tags

ACF Ajax Analytics API Bootstrap Breadcrumb category CPT CSS fetch FSE Genesis Google Maps Gutenberg HTML Isotope JavaScript jQuery loop Map Menu Parallax PHP Rest API SASS SEO SQL Storefront SVG tab tag manager tags Taxonomy Tool upsell Webpack Wholesale WooCommerce WordPress WPML

Disclosure: Some of the links in this site are affiliate links. I will be paid a commission if you use this link to make a purchase.

  • Privacy Policy / Terms of Service
© 2025 WP Flames - All Right Reserved