Reputation: 57
Im tring to get custom field value via functions.php using this code:
function discount_base_quantity(){
global $woocommerce;
global $post;
$product = $woocommerce->cart->get_cart();
foreach ($product as $key => $value) {
$product_id = wc_get_product($value['data']->get_id());
$field = get_post_meta($product_id,'option_a');
echo $field; }}
But it didnt work. what am i missing? is there another way to do that?
Upvotes: 0
Views: 954
Reputation: 57
I found my problem. actualy i didnt pass the product id in get_post_meta function. so this code is work for me:
function discount_base_quantity(){
global $woocommerce;
$product = $woocommerce->cart->get_cart();
foreach ($product as $key => $value) {
$id = $value['product_id'];
//echo $product_id;
$field = get_post_meta($id,'option_a', true);
echo $field;
}
}
Upvotes: 1