• Skip to main content
  • Skip to primary sidebar

WordPress, Genesis Framework and Storefront customization tutorials

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

Free

Display title of current Custom Post Type’s taxonomy

    $terms = get_the_terms( $post->ID, 'YOUR_TAXONOMY' ); 
    foreach($terms as $term) { 
        echo $term->name; 
        echo $term->slug; 
    } 

Filed Under: Free Tagged With: CPT, Taxonomy

jQuery Modal without Bootstrap

// =============================================================
// ENQUEUE SCRIPTS FOR MODAL
// =============================================================
function storefront_enqueue_style() {
    wp_enqueue_style('modal_css', '//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css', false);
}
add_action( 'wp_enqueue_scripts', 'storefront_enqueue_style' );
 
function storefront_enqueue_script() {
    wp_enqueue_script('modal_jquery', '//cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js', false);
    wp_enqueue_script('modal_js', '//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js', false);
}
add_action( 'wp_enqueue_scripts', 'storefront_enqueue_script' );

HTML

<!--HTML EMBEDDED INTO THE DOCUMENT-->
<div id="modal1" class="modal">
  <h2>Hello World</h2>
  <a href="#" rel="modal:close">Close</a>
</div>

<!--LINK TO OPEN THE MODAL-->

<p><a href="#modal1" rel="modal:open">Open Modal</a></p>

Filed Under: Free Tagged With: jQuery

How to select “Add to cart” button with jQuery

jQuery(document).ready(function() {
jQuery(‘body’).on(‘click’, ‘.add_to_cart_button’, function() {
jQuery(this)
alert(“HELLO”);
});
});

Filed Under: Free Tagged With: jQuery, WooCommerce

How to Change “Place Order” text in WooCommerce Checkout

// =============================================================
// CHANGE PLACE ORDER TEXT
// =============================================================
add_filter('woocommerce_order_button_html', 'change_place_order_button');

function change_place_order_button($button_html){
    $button_html = str_replace('Place order', 'Order Now', $button_html);
    return $button_html;
}

Filed Under: Free Tagged With: WooCommerce

Remove sidebar from cart and checkout page in Genesis WooCommerce

// =========================================================================
//REMOVE SIDEBAR OF GENESIS CHECKOUT AND CART PAGE 
// =========================================================================
function remove_checkout_sidebar_genesis($opt) {
    if( is_checkout() || is_cart()) {
       $opt = 'full-width-content';
        return $opt;
    }
}
add_filter('genesis_site_layout', 'remove_checkout_sidebar_genesis');

Filed Under: Free Tagged With: Genesis

Excluded TAX for specific user role in WooCommerce

function tax_excluded_price_per_user_role( $value ) {
    if ( current_user_can( 'wholesale_customer' ) ) {
        return 'excl';
    }
    return $value;
}
add_filter( 'pre_option_woocommerce_tax_display_shop', 'tax_excluded_price_per_user_role' );
add_filter( 'pre_option_woocommerce_tax_display_cart', 'tax_excluded_price_per_user_role' );

Filed Under: Free Tagged With: WooCommerce

Show the price in different currency on product archive page in WooCommerce

// =========================================================================
// SHOW PRICE IN EURO
// ========================================================================= 
function show_price_in_euro(){
    global $product;
    
     if( $product->has_child() ) {
        $product->get_id();
        $var_price_huf = $product->get_variation_price( 'min', true );
        $exchange_rate = 360;
        $price_eur = $var_price_huf / $exchange_rate;
        echo '<span class="price euro"><span class="woocommerce-Price-amount amount eur">'.round($price_eur, 1).' €</span></span>';
    }
    else{
        $product->get_id();
        $price_huf = $product->get_price(); 
        $exchange_rate = 360;
        $price_eur = $price_huf / $exchange_rate;
        echo '<span class="price euro"><span class="woocommerce-Price-amount amount eur">'.round($price_eur, 1).' €</span></span>';
    }
}
add_action('woocommerce_after_shop_loop_item', 'show_price_in_euro',-1);

Filed Under: Free Tagged With: WooCommerce

Specific Shipping Method Based on Minimum Order Amount in WooCommerce

// =========================================================================
// MINIMUM ORDER AMOUNT FOR SPECIFIC SHIPPING METHOD
// =========================================================================
function minimum_order_amount_for_shipping( $rates, $package ) {
   $threshold = 100;
   if ( WC()->cart->subtotal < $threshold ) {
         unset( $rates['flat_rate:2'] );
   } 
   return $rates;
}
add_filter( 'woocommerce_package_rates', 'minimum_order_amount_for_shipping', 10, 2 );

Filed Under: Free Tagged With: WooCommerce

How to show the percentage value of your discounts in WooCommerce

// =========================================================================
// SHOW THE PERCENTAGE VALUE OF DISCOUNT PRODUCTS
// =========================================================================
function woocommerce_custom_sales_price( $price, $regular_price, $sale_price ) {
    global $product;
    if( $product->has_child() ) {
        $var_regular_price = $product->get_variation_regular_price( 'min', true );
        $var_sale_price = $product->get_variation_price( 'min', true );
        
        $percentage = round( ( $var_regular_price - $var_sale_price ) / $var_regular_price * 100 ).'%';
        $percentage_txt = ' ' . __('<span class="sale-percentage"> -', 'woocommerce' , '</span>') . $percentage;
        $price = '<del>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del> <ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) . $percentage_txt : $sale_price . $percentage_txt ) . '</ins>';
        return $price;
    }
    else{
        $percentage = round( ( $regular_price - $sale_price ) / $regular_price * 100 ).'%';
        $percentage_txt = ' ' . __('<span class="sale-percentage"> -', 'woocommerce' , '</span>') . $percentage;
        $price = '<del>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del> <ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) . $percentage_txt : $sale_price . $percentage_txt ) . '</ins>';
        return $price;
    }
}
add_filter( 'woocommerce_format_sale_price', 'woocommerce_custom_sales_price', 10, 3 );

Filed Under: Free Tagged With: WooCommerce

Add extra fee based on shipping method in WooCommerce

// =========================================================================
// ADD EXTRA FEE BASED ON SHIPPING METHOD
// =========================================================================
add_action( 'woocommerce_cart_calculate_fees','wc_add_surcharge' ); 
function wc_add_surcharge() { 
    
    global $woocommerce; 

    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) 
        
    return;
    
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
          
    $chosen_shipping = $chosen_methods[0];
    
    $fee = 10;

    if ( $chosen_shipping == 'flat_rate:2' ) {
        $woocommerce->cart->add_fee( 'Extra fee: ', $fee, true, 'standard' );  
    }
}

Filed Under: Free Tagged With: WooCommerce

How to add Custom Terms and Conditions Checkbox to WooCommerce Checkout

// =========================================================================
// CUSTOM TERMS AND CONDITIONS CHECKBOX IN WOO
// =========================================================================
function add_checkbox_to_woocommerce_checkout() {
    ?>
    <p id="wpgdprc_field" class="form-row wpgdprc-checkbox validate-required">
       <span class="woocommerce-input-wrapper">
        <label class="checkbox">
            <input id="wpgdprc" type="checkbox" value="1" class="input-checkbox" name="wpgdprc" > 
            <span class="gdpr-privacy">I've read and accept the  <a target="_blank" href="/terms-and-conditions/">Terms and Conditions</a></span>
            <abbr class="wpgdprc-required required" title="This field is required">*</abbr>
        </label>
        </span>
      
    </p>
    <?php
}
add_action('woocommerce_checkout_after_terms_and_conditions', 'add_checkbox_to_woocommerce_checkout' );

Filed Under: Free Tagged With: WooCommerce

Display sticky post first, then the last published posts in Genesis

function custom_loop_with_pagination() {
    global $post;

    $sticky = get_option( 'sticky_posts' );
 
    $args = array(
        'paged'          => get_query_var( 'paged' ),
        
        'sticky_first' => array(
            'post_type'      => 'post', 
            'category_name'  => 'program',
            'post__in' => $sticky, 
            'posts_per_page' => 2,  
        ),
        'last_published' => array(
            'post_type'      => 'post', 
            'category_name'  => 'program',
            'post__not_in' => $sticky, 
            'posts_per_page' => 10,
            
        )
        
    );
 
    global $wp_query;
    $wp_query = new WP_Query( $args );
    
    require 'templates/loop/grid.php';

}
add_action( 'genesis_loop', 'custom_loop_with_pagination' );
add_action( 'genesis_before_loop', 'genesis_posts_nav' );
 
 
genesis();

Filed Under: Free Tagged With: Genesis

Change the excerpt more filter

Filed Under: Free

Add custom og:image with customizer if latest post is set to the front page

// =========================================================================
// ADD OPEN GRAPH IMAGE UPLOAD OPTION TO CUSTOMIZER
// =========================================================================
function og_image_customize_register( $wp_customize ) {
 
    // Add Settings
    $wp_customize->add_setting('customizer_setting_og_image', array(
        'transport'         => 'refresh',
    ));
 
    // Add Section
    $wp_customize->add_section('og_section', array(
        'title'             => __('Open Graph image', 'name-theme'), 
        'priority'          => 70,
    ));    
 
    // Add Controls
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'customizer_setting_og_image', array(
        'label'             => __('Add Open Graph image', 'name-theme'),
        'section'           => 'og_section',
        'settings'          => 'customizer_setting_og_image',    
    )));
}
add_action('customize_register', 'og_image_customize_register');

// =========================================================================
// HOOK THE OG IMAGE INTO THE HOME PAGE
// ========================================================================= 
function add_og_image_to_homepage() { 
    if(is_front_page()){
        $og_image = esc_url( get_theme_mod( 'customizer_setting_og_image' ) );
        echo '<meta property="og:image" content="'.$og_image.'" />';
    }
 } 
add_action('wp_head', 'add_og_image_to_homepage');

Filed Under: Free Tagged With: PHP

Custom single post template for specific category in Genesis

Add this snippet to single.php

<?php
  
function custom_single_post() { 
        
        if(in_category('program')){
            include('single-CATEGORY_1.php');
        }elseif(in_category('piacter')){
            include('single-CATEGORY_2.php');    
        }else{
            include('single.php');
        }
   }
   add_action('genesis_before_loop', 'custom_single_post', 0);

genesis();

Filed Under: Free Tagged With: Genesis

Echo something if post has specific category

You should put this snippet inside the loop

if ( in_category('CATEGORY_NAME')){
        echo 'Hello World!';
    }

Filed Under: Free Tagged With: PHP

Visual Studio Code with Live Server and Live SASS Compiler on Localhost

Filed Under: Free Tagged With: SASS

Custom Post Type with Pagination in Genesis

Do You want to create a Custom Post Type loop with the Genesis core pagination? In this post I’m gonna show You how to do it.

1) Create a Custom Post Type and add some posts to it

You can create a Custom Post Type with code, or You can use a plugin like Custom Post Type UI to do it.

pagination-01

2) Create a new page named Pagination and leave it blank

pagination-02

3) Create a genesis template file named page-pagination.php and place this code into it

If You set the slug of the previous created page after the file name page.php -> page-pagination.php, You don’t need to specify the Template name: Pagination right after the opening php tag.

<?php
// =========================================================================
// CUSTOM POST TYPE WITH PAGINATION
// =========================================================================
function custom_loop_with_pagination() {
	global $post;

	$args = array(
		'post_type'      => 'books',  //---YOUR CUSTOM POST TYPE
		'posts_per_page' => 4,        //---SET HOW MANY POSTS MUST BE SHOWN ON ONE PAGE
		'paged'          => get_query_var( 'paged' )
	);

	global $wp_query;
	$wp_query = new WP_Query( $args );

	if ( have_posts() ) : 
		while ( have_posts() ) : the_post(); ?>
            
            <article>
                <h2><?php the_title(); ?></h2>
                <?php the_excerpt(); ?>
			</article>

		<?php endwhile;
		do_action( 'genesis_after_endwhile' );
	endif;

	wp_reset_query();
}
add_action( 'genesis_loop', 'custom_loop_with_pagination' );
remove_action( 'genesis_loop', 'genesis_do_loop' );


genesis();

4) The result will be look like this

pagination

Filed Under: Free Tagged With: Genesis

How to add Pagination to the Archive of Custom Post Type in any WordPress Theme

Pagination function

Create a file named pagination.php in yout child theme and include it in your functions.php

<?php 
// numbered pagination
function pagination($pages = '', $range = 4)
{  
     $showitems = ($range * 2)+1;  
  
     global $paged;
     if(empty($paged)) $paged = 1;
  
     if($pages == '')
     {
         global $the_query;
         $pages = $the_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   
  
     if(1 != $pages)
     {
         echo "<div class=\"archive-pagination pagination\">";
         echo "<ul>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'> 
         <span class='double-chevron-wrapper'>
                <i class='fas fa-chevron-left first'></i>
                <i class='fas fa-chevron-left second'></i>
         </span>
            </a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'> <i class='fas fa-chevron-left prev'></i></a>";
  
         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<li><span class=\"current\">".$i."</span></li>":"<li><a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a></li>";
             }
         }
  
         if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\"><i class='fas fa-chevron-right next'></i></a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>
            <span class='double-chevron-wrapper'>
                <i class='fas fa-chevron-right first'></i>
                <i class='fas fa-chevron-right second'></i>
            </span>
            </a>";
         echo "</ul>\n";
         echo "</div>\n";
          
         echo "<div class='all_pages'><small>Current page: ".$paged." All pages ".$pages."</small></div>";
     }
}

?>

Create the WordPress Loop

Add the name of your terms

Set the posts_per_page value in the args

<?php
wp_reset_postdata();

$terms_name = 'YOUR_TERMS_NAME';

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  
$args = array(
    'post_type' => 'YOUR_POST_TYPE',
    'posts_per_page' => 2,
    'paged' => $paged,
    'tax_query' => array(
               array(
                   'taxonomy' => 'YOUR_TAXONOMY',
                   'field'    => 'slug',
                   'terms'    => $terms_name
               ),
           ),
);
  
$the_query = new WP_Query( $args ); ?>

    <!--YOUT CUSTOM CONTENT-->
    
    <h2><?php the_title(); ?></h2>

<?php echo pagination($the_query->max_num_pages); ?>

Add some line of CSS

.archive-pagination.pagination li {
	margin-left: 0 !important;
	margin-right: 10px !important;
}
.current {
	padding: 0.9rem 1.2rem;
	background: #124e84;
    color: white;
}

Filed Under: Free Tagged With: WordPress

Echo something conditionally on the single page of specific Custom Post Type Taxonomy

// ==================================================================
// SINGLE PAGE OF SPECIFIC CPT TAXONOMY
// ==================================================================
function single_page_of_specific_cpt_taxonomy(){
    global $post; 
    if(is_singular('YOUR_CPT')){
       foreach (get_the_terms(get_the_ID(), 'YOUR_TAXONOMY') as $cat) {
           //echo $cat->slug;
           if($cat->slug === 'YOUR_TERM'){
               echo 'YEAHHH!!!!';
           }
        }
    }
}
add_action('genesis_entry_content', 'single_page_of_specific_cpt_taxonomy');

Filed Under: Free Tagged With: CPT

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 7
  • Page 8
  • Page 9
  • Page 10
  • Page 11
  • Interim pages omitted …
  • Page 19
  • 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