WC Attributes - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of WC Attributes.php

  1. <?php
  2. global $product;
  3. // Get product attributes
  4. $attributes = $product->get_attributes();
  5.  
  6. foreach ( $attributes as $attribute ): ?>
  7.         <br><b><?php $attrnames = str_replace("pa_", "", $attribute['name']);
  8.         echo str_replace("-", " ", $attrnames);
  9.         ?></b><br>
  10.         <i><?php $attrvalue = array( wc_get_product_terms( get_the_ID(), $attribute['name'], array( 'fields' => 'names' ) ) );
  11.         $attrvalues = implode(",", $attrvalue[0]);
  12.         echo $attrvalues;
  13.             ?></i>
  14. <?php
  15. endforeach;
File Description
  • WC Attributes
  • PHP Code
  • 22 Oct-2020
  • 519 Bytes
You can Share it: