Created
November 22, 2017 12:40
-
-
Save eto4detak/7a1b52b88532426ac58bc9f810a8cccc to your computer and use it in GitHub Desktop.
wp php get_posts WC_Product_Variation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_type' => 'product_variation', | |
'post_status' => array( 'private', 'publish' ), | |
'numberposts' => -1, | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'post_parent' => get_the_ID() // get parent post-ID | |
); | |
$variations = get_posts( $args ); | |
foreach ( $variations as $variation ) { | |
// get variation ID | |
$variation_ID = $variation->ID; | |
// get variations meta | |
$product_variation = new WC_Product_Variation( $variation_ID ); | |
// get variation featured image | |
$variation_image = $product_variation->get_image(); | |
var_dump($variation_image); | |
// get variation price | |
$variation_price = $product_variation->get_price_html(); | |
//get variation name | |
$variation_name = $product_variation->get_variation_attributes(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment