PHP Developers Network
http://forums.devnetwork.net/

I need to write a Wordpress Function, but really stuck
http://forums.devnetwork.net/viewtopic.php?f=1&t=147875
Page 1 of 1

Author:  simonmlewis [ Wed Feb 13, 2019 5:32 am ]
Post subject:  I need to write a Wordpress Function, but really stuck

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.

Author:  Celauran [ Thu Feb 14, 2019 6:40 pm ]
Post subject:  Re: I need to write a Wordpress Function, but really stuck

What have you tried so far and where are you getting stuck?

Author:  simonmlewis [ Fri Feb 15, 2019 4:23 am ]
Post subject:  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.

Syntax: [ Download ] [ Hide ]
// 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 );

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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/