You will need to use the methods on one of the WooCommerce product object
for example:
function insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
echo '<meta property="og:title" content="' . get_the_title() . '"/>';
echo '<meta property="og:type" content="article"/>';
echo '<meta property="og:url" content="' . get_permalink() . '"/>';
echo '<meta property="og:site_name" content="My Website"/>';
if( isset( $gallery_image_ids[1] ) ) { //the post does not have featured image, use a default image
$default_image="https://www.website.com"; //replace this with a default image on your server or an image in your media library
echo '<meta property="og:image" content="' . $default_image . '"/>';
}
else{
$product = wc_get_product($post->ID);
$image = wp_get_attachment_image_src($product->get_image_id(), 'full');
echo '<meta property="og:image" content="' . $image . '"/>';
}
echo "
";
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );