WordPress Codesnippets

woocommerce get product image by id


This code retrieves the image URL associated with a given product ID. The first line calls the wc_get_product_image_id() function which retrieves the image ID from the product ID. Next, the wp_get_attachment_url() function is used to retrieve the URL of the image attached to the image ID. The result is the URL of the image associated with the product.

Was this code snippet helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmatically save post

This code creates a WordPress post with the values of the ‘post_title’ and ‘post_content’ variables. It sets the post status to ‘publish’ and the author

Read More »

Create order programmatically

This code creates a new post in the WordPress database with post type ‘shop_order’, post title ‘Order #12345’, post status ‘wc-processing’, and ping status ‘closed’.

Read More »