2
votes

i am currently developing an extension for woocommerce. I am hooking into the admin variations tab like this:

add_action( 'woocommerce_product_after_variable_attributes' ,'wwp_add_variable_wholesale_price' );

function wwp_add_variable_wholesale_price(){

    global $post, $woocommerce;
    $post_id = $post->ID;
    echo $post_id;

}

Them above is currently displayin the parent product id, and not the variation id. Does anyone know how to get the actual variation id?

1
It seems hard to help without more context. Do you have more code you can post? What framework are you using? How are the database tables structured, if there are any? - murftown
i am using wordpress. No this is all the code i have created. Everything else is generated by wordpress / woocommerce. - danyo
So you're using the posts to store different products, 1 post per product? - murftown
yes that's how woocommerce works. it will then store a variation of that product as a separate post. - danyo
Gotcha. No experience with woocommerce, best of luck though! - murftown

1 Answers

0
votes

Add the action like this:

add_action( 'woocommerce_product_after_variable_attributes', 'wwp_add_variable_wholesale_price', 10, 3);

function wwp_add_variable_wholesale_price($loop, $variation_data, $variation){

global $post, $woocommerce;
$post_id = $variation->ID;
echo $post_id;

}