• Skip to main content
  • Skip to primary sidebar

WordPress, Genesis Framework and Storefront customization tutorials

  • Archive
    • Genesis
    • WooCommerce
    • WordPress
  • Premium
  • Blog
  • About
    • Tools I Use
  • Contact
  • Login
Home » Archives for Gabor » Page 8

Gabor

Add product category to body class

2018-05-13 by Gabor


//ADD PRODUCT CATEGORY TO BODY CLASS

add_filter( 'body_class', 'bbloomer_wc_product_cats_css_body_class' );

function bbloomer_wc_product_cats_css_body_class( $classes ){
if( is_singular( 'product' ) )
{
$custom_terms = get_the_terms(0, 'product_cat');
if ($custom_terms) {
foreach ($custom_terms as $custom_term) {
$classes[] = 'product_cat_' . $custom_term->slug;
}
}
}
return $classes;
}

Filed Under: WooCommerce Tagged With: body class, category

Add text to specific product category

2018-05-13 by Gabor

Version 1

// =========================================================================
// ADD TEXT TO SPECIFIC PRODUCT CATEGORY
// =========================================================================
function function_name( $attr ) {
    global $product;
    if ( has_term( 'category_name', 'product_cat', $product->get_id() ) ) {
        echo 'TESZT';
    }
    return $attr;
}
add_filter( 'woocommerce_share', 'function_name' );

Version 2


// =========================================================================
// ADD TEXT TO SPECIFIC PRODUCT CATEGORY
// =========================================================================
function add_text_to_spec_cat() {
    global $post;
    $terms = wp_get_post_terms( $post->ID, 'product_cat' );
    foreach ( $terms as $term ) $categories[] = $term->slug;
    if ( in_array( 'szivar', $categories ) ) {
        echo 'TESZT';
    }
}
add_filter( 'woocommerce_after_single_product', 'add_text_to_spec_cat' );

Filed Under: WooCommerce

Change position of add-to-cart on single product

2018-05-13 by Gabor


remove_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_price', 30 );

Filed Under: WooCommerce

Hook revslider in Storefront

2018-05-13 by Gabor


//HOOK REVSLIDER
add_filter( 'storefront_before_content', 'add_revslider' );

function add_revslider( $rev_slider ) {
    if ( is_front_page() ) {
        echo do_shortcode('[rev_slider alias="revslider"]');
    }
return $rev_slider;
}

Filed Under: WooCommerce Tagged With: slider

Fix collapsed related products

2018-05-13 by Gabor


//FIX COLLAPSED RELATED PRODUCTS
add_filter( 'woocommerce_after_single_product_summary', 'add_clear_both' );
function add_clear_both( $clear_both ) {
echo '<div class="clear"></div>';
return $clear_both;
}

Filed Under: WooCommerce

Add text via function

2018-05-13 by Gabor


//ADD TEXT VIA FUNCTION
add_filter( 'ultimatum_print_footer', 'add_barion_banner' );
function add_barion_banner( $barion_banner ) {
echo 'TESZT';
return $barion_banner;
}

Filed Under: PHP

Product category shortcode

2018-05-13 by Gabor

[product_category category=”” per_page=”40″ columns=”3″ orderby=”rand”]

Filed Under: WooCommerce

New order e-mail custom text if coupon is used

2018-05-13 by Gabor Leave a Comment

// New order e-mail custom text if coupon is used
add_filter( 'woocommerce_email_after_order_table', 'add_custom_email_text' );

function add_custom_email_text($order) {
if ($order->get_used_coupons()){
echo '';
}
else{
echo '';
}
}

Filed Under: WooCommerce

Redirect after registration

2018-05-13 by Gabor Leave a Comment


//Redirect after registration
add_filter( 'woocommerce_registration_redirect', 'custom_redirection_after_registration', 10, 1 );
function custom_redirection_after_registration( $redirection_url ){
if ( WC()->cart->get_cart_contents_count() == 0 ) {
$redirection_url = get_permalink( wc_get_page_id( 'shop' ) );

}else{

// Change the redirection Url
$redirection_url = wc_get_checkout_url(); //Checkout
}

return $redirection_url; // Always return something
}

/*
"Home" Url: $redirection_url = get_home_url();
"Shop" Url: $redirection_url = get_permalink( wc_get_page_id( 'shop' ) );
"Cart" Url: $redirection_url = wc_get_cart_url();
"Checkout" Url: $redirection_url = wc_get_checkout_url();
"Account" $redirection_url = get_permalink( wc_get_page_id( 'myaccount' ) );
"ID": $redirection_url = get_permalink( $post_id );
(where $post_id is the id of the post or the page)
Get post or pages by path (example): $redirection_url = home_url('/product/ninja/');
*/

Filed Under: WooCommerce

Exclude products from specific category in shop page

2018-05-13 by Gabor Leave a Comment


/**
* EXCLUDE PRODUCTS FROM SPECIFIC CATEGORY IN SHOP PAGE
*/
function custom_pre_get_posts_query( $q ) {

$tax_query = (array) $q-&gt;get( 'tax_query' );

$tax_query[] = array(
'taxonomy' =&gt; 'product_cat',
'field' =&gt; 'slug',
'terms' =&gt; array( 'havi-meglepetes-palinkacsomagok' ), // Don't display products in the clothing category on the shop page.
'operator' =&gt; 'NOT IN'
);

$q-&gt;set( 'tax_query', $tax_query );

}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

Filed Under: WooCommerce

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 6
  • Go to page 7
  • Go to page 8

Primary Sidebar

  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
WP Rocket - WordPress Caching Plugin
UpdraftPlus Premium

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
  • Flames Design
© 2021 WP Flames - All Right Reserved