PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Jan 24, 2020 1:08 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Jan 25, 2018 8:24 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
Hi there.
We are getting errors on the implode code.
Is the current version of PHP using this differently now??
Error is PHP Warning: implode(): Invalid arguments passed.

Syntax: [ Download ] [ Hide ]
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_echo_stock_variations_loop' );
 
function bbloomer_echo_stock_variations_loop(){
global $product;
    if ($product->get_type() == 'variable') {
        foreach ($product->get_available_variations() as $key) {
        $attr_string = '';
            foreach ( $key['attributes'] as $attr_name => $attr_value) {
                                $attr_string[] = $attr_value;
            }
            if ( $key['max_qty'] > 0 ) { echo '' . implode(', ', $attr_string) . ': ' . $key['max_qty'] .' in stock<br/>'; } else { echo '' . implode(', ', $attr_string) . ': out of stock<br/>'; }
            }
    }
}

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


Top
 Profile  
 
PostPosted: Thu Jan 25, 2018 1:39 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria
Syntax: [ Download ] [ Hide ]
$attr_string = '';

and if there are no $key['attributes'] items then you have an error (implode expects as 2nd param an array, not a string).

Try instead:
Syntax: [ Download ] [ Hide ]
$attr_string = [];

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
PostPosted: Thu Jan 25, 2018 1:44 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
Great thanks. Is it bad code or just old code?

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


Top
 Profile  
 
PostPosted: Fri Jan 26, 2018 6:46 am 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
PostPosted: Fri Jan 26, 2018 6:57 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
Wow - ok. It was taken from a website called Business Bloomer.

_________________
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  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 6 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:  
Powered by phpBB® Forum Software © phpBB Group