Woocommerce checkout field

Try : add_filter( ‘woocommerce_checkout_fields’ , ‘custom_override_checkout_fields’ ); function custom_override_checkout_fields( $fields ) { if(is_user_logged_in()){ unset($fields[‘billing’][‘billing_email’]); } return $fields; } Source : https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

How to rewrite wordpress search to work on specific category

You can use add_rewrite_rule(): add_action( ‘init’, function(){ // Non-paged requests. E.g. example.com/categoryname/search/keyword/ add_rewrite_rule( ‘^categoryname/search/([^/]+)/?$’, ‘index.php?category=categoryname&s=$matches[1]’, ‘top’ ); // For paged requests. E.g. example.com/categoryname/search/keyword/page/2/ add_rewrite_rule( ‘^categoryname/search/([^/]+)/page/(\d+)/?$’, ‘index.php?category=categoryname&s=$matches[1]&paged=$matches[2]’, ‘top’ ); } ); Be sure to flush the permalinks — simply visit the Permalink Settings page.

add_filter to specific WooCommerce Category

To account for variations, I’d suggest using $product->get_category_ids() and checking if your category is in there: function wcs_custom_get_availability( $availability, $_product ) { $workshops_category = get_term_by( ‘slug’, ‘workshops’, ‘product_cat’ ); $product_category_ids = $_product->get_category_ids(); if ( ! in_array( $workshops_category->term_id, $product_category_ids ) ) { return $availability; } // Change In Stock Text if ( $_product->is_in_stock() ) { $availability[‘availability’] … Read more

How to append classname to body tag if guest user

Yes, there’s the body_class filter. You could use e.g. function body_class_guest_user( $classes, $class ) { if ( ! is_user_logged_in() ) { $classes[] = ‘guest-user’; } return $classes; } add_filter( ‘body_class’, ‘body_class_guest_user’, 10, 2 ); However you could equally well just use the :not() selector, e.g. body:not(.logged-in) (browser support), or absence of logged-in i.e. set up … Read more

Show some menu sub items as dropdown under a menu item

Remove the first closing </li> and wrap the sub-items inside <ul></ul>, then close the parent <li>. For Example: function my_custom_menu_item($items, $args) { if(is_user_logged_in() && $args->theme_location == ‘primary’) { $user=wp_get_current_user(); $name=$user->display_name; $items .= ‘<li><a href=””>’.$name.'</a>’; $items .= ‘<ul>’; $items .= ‘<li><a href=”http://wordpress.stackexchange.com/my-profile”>My Profile</a></li>’; $items .= ‘<li><a href=”http://wordpress.stackexchange.com/my-posts”>My Posts</a></li>’; $items .= ‘<ul>’; $items .= ‘</li>’; } return … Read more

Using Static HTML instead of the `home_url()` WP function

href=”https://wordpress.stackexchange.com/questions/350287/./contact-page” if you’re on the homepage (/) this will become: /contact-page if you’re on another page named foo (/foo/) this will become /foo/contact-page This is due to ./ being a relative path. To avoid struggles like this, the method via home_url() is preferred because it creates absolute links/paths that will work from anywhere you call … Read more