fabricio31 on "[Plugin: WooCommerce] SIdebar widget showing products of same categories"

ساخت وبلاگ

That's what I did:
- in function.php of my child theme I added the following snippet to execute php code in text widget

// Enable PHP in widgets
add_filter('widget_text','execute_php',100);
function execute_php($html){ if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html); $html=ob_get_contents(); ob_end_clean(); } retu $html;

- then when I saw the snippet runs ok I added that code to test it:

<?php $prod=get_the_term_list( $post->ID, 'product_cat', '', '', '' );
echo $prod; ?>

and all worked fine gaving me the exact name of current category of the product displayed in single product page!
- So I've tried another test to view if a shortcode translated in php should works in a widget too (writing at this time the exact category name requested...in this case sportcar):
<?php echo do_shortcode('[product_category category="sportcar" per_page="20" columns="1" orderby="title" order="desc"]'); ?>
and all was again well done!
- Finally I mixed all in this code and something goes wrong:

<?php $prod=get_the_term_list( $post->ID, 'product_cat', '', '', '' );
echo do_shortcode('[product_category category="'.$prod.'" per_page="20" columns="1" orderby="title" order="desc"]'); ?>

In last case the code don't display anything... I don't understand where I make mistakes...the syntax is wrong or the solving approach is illogical?
I really appreciate any comment about it.
Thanks again.

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 285 تاريخ : سه شنبه 25 خرداد 1395 ساعت: 7:33