add meta key and meta value to post in wordpress programmatically (woocommerce)

696 views Asked by At

I woud like to add custom meta key and meta value in wordpress post for woocommerce products. I have code like this:

        global $wpdb;
$post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1" );
add_post_meta($post_id, 'offers_for_woocommerce_enabled', 'yes’, true);
add_post_meta($post_id, 'woo_ua_product_condition', 'used', true);
add_post_meta($post_id, 'woo_ua_opening_price', 1, true);
add_post_meta($post_id, 'woo_ua_lowest_price', 2, true);

and I've received the error: Parse error: syntax error, unexpected 'woo_ua_product_condition' (T_STRING), expecting ')' in ...

pls help

1

There are 1 answers

0
Josh Bonnick On BEST ANSWER

You have a different quotation mark in this line add_post_meta($post_id, 'offers_for_woocommerce_enabled', 'yes’, true);

Replace with this

add_post_meta($post_id, 'offers_for_woocommerce_enabled', 'yes', true);