Skip to content

Instantly share code, notes, and snippets.

@emoop
emoop / custom field filter
Created February 17, 2014 21:07
Get product custom field when get product in Woocmmerce REST API
<?php
/* if you have get a custom field use this filter*/
add_filter('woocommerce_api_product_response','get_custom_field');
// '_brand' is my custom field
function get_custom_field($product){
$product['brand']=get_post_meta($product['id'],'_brand',true);
return $product;
}
@emoop
emoop / woocommerce-display-attributes-for-product-in-catalog
Created March 12, 2017 19:18
Display attributes names for each product in shop catalog in format like "size:x,xxl"
add_action( 'woocommerce_after_shop_loop_item_title','display_sizes' );
function display_sizes(){
global $product;
$variations=$product->get_available_variations();
$count=sizeof($variations);
$counter=0;
echo '<span class="sizes">Sizes:';//sizes or whatever u want
foreach($variations as $var){
foreach($var['attributes'] as $name=>$val){