Having trouble getting the custom_field value to use as a variable for custom variation pricing on woocommerce. I have a custom field within every product, hope to use this number to divide by giving me a price per unit. Does this make any sense?
add_filter( 'woocommerce_available_variation', 'bbloomer_add_custom_field_variation_data' );
function bbloomer_add_custom_field_variation_data( $variations ) {
$variations['custom_field'] = get_post_meta( $variations[ 'variation_id' ], 'custom_field', true );
$divider =(int)$variations['custom_field'];
echo $divider;
return $variations;
}
function return_custom_price($price, $product) {
global $post, $blog_id;
$price = get_post_meta($post->ID, '_regular_price');
$post_id = $post->ID;
$price = ($price[0]/ $divider);
return $price;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);