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.
Result of php executing
Full code of WC Attributes.php
- <?php
- global $product;
- // Get product attributes
- $attributes = $product->get_attributes();
- foreach ( $attributes as $attribute ): ?>
- <br><b><?php $attrnames = str_replace("pa_", "", $attribute['name']);
- echo str_replace("-", " ", $attrnames);
- ?></b><br>
- <i><?php $attrvalue = array( wc_get_product_terms( get_the_ID(), $attribute['name'], array( 'fields' => 'names' ) ) );
- $attrvalues = implode(",", $attrvalue[0]);
- echo $attrvalues;
- ?></i>
- <?php
- endforeach;