wordpress - PHP Woocomerce get product brand name -


i create plugin , want brand name woocomerce. in fist time post product no.1 plugin it's work , product brand wish when create product post no.2 , no.3 brand name product no.1

whats wrong ?

if ( class_exists( 'woocommerce' ) ) {         $kode = $product->get_sku();         $terms = wp_get_post_terms( $product_id, 'brand', array('orderby'=>'name'));          $brands = get_terms( 'brand', array(         'orderby'       => 'name'         //,'product__in'  => $product->id         // orderby arguments ('name', 'slug','term_group', 'term_id', 'id', 'description')         ) );          foreach ( $brands $key => $brand ) :             $brand_name = $brand->name;         endforeach;          $merk = $brand_name;          //this want print brand name         echo "<strong>stock ".$merk." ".$kode."</strong><br/>";       } else {       echo "please active woocommerce plugin.";     } 

please help, thank you.

this should work you.

if ( class_exists( 'woocommerce' ) ) {         $kode = $product->get_sku();          $tax = array(         'stock'=>'brand',          );          foreach ($tax $mk_label => $mk_value) {             $make_array = wp_get_post_terms(get_the_id(), $mk_value, array("fields" => "names"));             foreach ($make_array $value) {                 $mk .= $value.", ";             }             echo '<strong>'.$mk_label.' <a href="javascript:void(0)">'.rtrim($mk,", ").' '.$kode.'</a></strong>';             $mk ="";         }       } else {       echo "please active woocommerce plugin.";     } 

we taking terms dynamically based on current product id , fetching brand accordingly. let me know if need more help.

thanks


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -