My code is:
function sync_on_product_save($new_status, $old_status, $post) {
global $post;
global $product;
if(
$old_status != 'publish'
&& $new_status == 'publish'
&& !empty($post->ID)
&& in_array( $post->post_type,
array( 'product')
)
) {
print_R($product);
}
}
add_action('transition_post_status', 'sync_on_product_save', 10, 3);
I want to pass the product price, sku, description, and name to third-party API.
Please help me.
$post
object is passed via the action and through that you pretty much have access to what you need. However, to answer the question about the$product
object specifically, you need to give it a product ID (which is the post ID) to have it contain anything where you're trying to access it. See my answer below which provides a solution using the product object.