Hi
Not sure if this is the right place to ask this. I've used this forum extensively for PHP coding and learnt a massive amount, but this is about Wordpress.
There are tutorials on how to do functions, but they are all about writing "hello there" in the header or footer of Wordpress; not how to tap into an existing bit of code and edit it.
Here's what we need:
To take the Woocommerce Brands plugin, find it's brand entry (ie. brand-name), and add that into the shop/archive pages, so that you get:
Product Title
£price
Brand name
Maybe someone can help.
I need to write a Wordpress Function, but really stuck
Moderator: General Moderators
-
- DevNet Master
- Posts: 4434
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
I need to write a Wordpress Function, but really stuck
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: I need to write a Wordpress Function, but really stuck
What have you tried so far and where are you getting stuck?
-
- DevNet Master
- Posts: 4434
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: I need to write a Wordpress Function, but really stuck
This is where I am going blind down an alley, with no idea where any door is.
So I found a function that should extract brand name, but I think it is more for other parts of the site, but it's a start.
I assumed this would gather the product_brand from the array, based on the $post->id in the loop.
Then it would echo that on screen after the title. It does echo 'here'. So the function isn't producing a fatal error.
My issue is I never know how to:
a) find the term within the database and then;
b) how to say 'select term from db where postid = $postid'.
It's not like a mysql query is it, but I REALLY want to learn it. I don't really want someone to just paste in the answer. I want to know that means that, this bit relates to this part of the database, and that renders that.
So I found a function that should extract brand name, but I think it is more for other parts of the site, but it's a start.
Code: Select all
// add brand to archive pages
function bbloomer_show_woocommerce_brands_loop($productBrandTerm) {
$productBrandTerm = wp_get_post_terms( $post->id, 'product_brand', array("fields" => "name"));
print_r($post->id);
echo '<div>here'.$productBrandName.'</div>';
}
add_action( 'woocommerce_after_shop_loop_item_title', 'bbloomer_show_woocommerce_brands_loop', 8 );
Then it would echo that on screen after the title. It does echo 'here'. So the function isn't producing a fatal error.
My issue is I never know how to:
a) find the term within the database and then;
b) how to say 'select term from db where postid = $postid'.
It's not like a mysql query is it, but I REALLY want to learn it. I don't really want someone to just paste in the answer. I want to know that means that, this bit relates to this part of the database, and that renders that.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.