PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Aug 24, 2019 10:36 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Feb 13, 2019 5:32 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
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.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Thu Feb 14, 2019 6:40 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
What have you tried so far and where are you getting stuck?

_________________


Top
 Profile  
 
PostPosted: Fri Feb 15, 2019 4:23 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
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.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group