Custom Taxonomy Select Menu: Setting default option value?

Simply add an extra line before your for loop. For example: function get_color_dropdown($taxonomies, $args){ $myterms = get_terms($taxonomies, $args); $output =”<select onChange=”window.location.href=this.value”>”; $output .= “<option value=”default”>Shop by Color –></option>”; foreach($myterms as $term){ $root_url = get_bloginfo(‘url’); $term_taxonomy=$term->taxonomy; $term_slug=$term->slug; $term_name =$term->name; $link = $root_url.”https://wordpress.stackexchange.com/”.$term_taxonomy.”https://wordpress.stackexchange.com/”.$term_slug; $output .=”<option value=””.$link.””>”.$term_name.”</option>”; } $output .=”</select>”; return $output; } $taxonomies = array(‘pa_color’); $args = … Read more

Customizing $product->get_title() function

In WooCommerce, the product variants are children of the actual product. So perhaps just check if the $product_id you’re on is a child, and if so get the title of the parent. Untested code: // Check if product has parent if($product->post_parent){ $parents = get_post_ancestors( $product->ID ); /* Get the top Level page->ID count base 1, … Read more

How to add category and subcategory in WordPress custom code?

The syntax for adding an action in WordPress WITHIN a class is somewhat different. Your code will have to look somewhat more like the following… class MyPluginClass { public function __construct() { add_action( ‘init’, array( $this, ‘sample_insert_category’) ); } public function sample_insert_category() { if(!term_exists(‘sample-category’)) { wp_insert_term( ‘Sample Category’, ‘category’, array( ‘description’ => ‘This is an … Read more

WooCommerce print subcategory of product

Configure, product_id and parent_category_id according to your requirements. /* This is product id */ $product_id = 1; /* This is the id of the parent category */ $parent_category_id = 8; $cats = get_categories ( array ( ‘type’ => ‘product’, ‘parent’ => $parent_category_id, ‘orderby’ => ‘term_group’, ‘hide_empty’ => true, ‘hierarchical’ = > 1, ‘exclude’ => ”, … Read more

I want to filter my products with attributes [closed]

As per what I understood from your question, you want two things – Listing of all publisher Listing of all books of a particular publisher. Here is code for both. Listing of all publisher $terms = get_terms( ‘pa_publisher’ ); echo ‘<ul>’; foreach ($terms as $each_term) { echo ‘<li>’.$each_term->name.'</li>’; } echo ‘</ul>’; Listing of all books … Read more