In includes/wc-template-hooks.php we can find:
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
So change priority from 20
add_action( 'woocommerce_after_shop_loop_item_title', 'woo_show_product_id', 20);
To 4 to display your custom field just before the star ratings
add_action( 'woocommerce_after_shop_loop_item_title', 'woo_show_product_id', 4 );
Priority: Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. Default value: 10
Note: use $product->get_id(); as of WooCommerce 3.0
So to answer your question, you can use
- via
woocommerce_after_shop_loop_item_title
function woo_show_product_id() {
global $product;
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
// Get Product ID
echo $product->get_id();
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'woo_show_product_id', 4 );
OR
some other hook from includes/wc-template-hooks.php
add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
And then you get with priority 11
- via
woocommerce_shop_loop_item_title
function woo_show_product_id() {
global $product;
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
// Get Product ID
echo $product->get_id();
}
}
add_action( 'woocommerce_shop_loop_item_title', 'woo_show_product_id', 11 );