//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;
}
WooCommerce
Add text to specific product category
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' );
Change position of add-to-cart on single product
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 30 );
Fix collapsed related products
//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;
}
Product category shortcode
[product_category category=”” per_page=”40″ columns=”3″ orderby=”rand”]
New order e-mail custom text if coupon is used
// 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 '';
}
}
Redirect after registration
//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/');
*/