I have added a Metabox with a custom input field to admin products using the following code (added in the functions.php file):
// ****************************** COUNTRY ********************************
// /*
// |--------------------------------------------------------------------------
// | ADD CUSTOM PRODUCT META BOX - PAIS made in 10:37 07.10.2020
// | WOOCOMMERCE - PRODUTOS - EDITAR PRODUTO
// |--------------------------------------------------------------------------
// */
add_action( 'add_meta_boxes', 'add_product_metas_box_country', 50 );
function add_product_metas_box_country(){
add_meta_box( "options-country", __("Country Name"),'product_metas_box_country_content_callback', 'product', 'normal', 'high' );
}
// /*
// |--------------------------------------------------------------------------
// | ADD CUSTOM PRODUCT META BOX HTML INPUT - PAIS made in 10:37 07.10.2020
// | WOOCOMMERCE - PRODUTOS - EDITAR PRODUTO
// |--------------------------------------------------------------------------
// */
function product_metas_box_country_content_callback( $post ) {
$value = get_post_meta( $post->ID, 'country', true );
echo '<div id="mdiv">
<input type="text" style="width: 100%" name="country" value="'. $value .'" id="country" spellcheck="true" autocomplete="off" placeholder="'. __('Insira País') .'">
</div>';
}
///*
// |--------------------------------------------------------------------------
// | SAVE COUNTRY CUSTOM FIELD VALUE - PAIS made in 10:37 07.10.2020
// | WOOCOMMERCE - PRODUTOS - EDITAR PRODUTO
// |--------------------------------------------------------------------------
// */
add_action( 'woocommerce_admin_process_product_object', 'save_product_country_meta_value' );
function save_product_country_meta_value( $product ) {
if( isset($_POST['country']) ) {
$product->update_meta_data( 'country', sanitize_text_field( $_POST['country'] ) );
}
}
And it works:
Now The text that I insert in that custom input field must be shown BETWEEN the Product Title and the Price.
The Goal is to insert 5 or more different Texts BETWEEN the Product Title and the Price, in List Format, AND for individual products.
Accordingly with WooCommerce Archive Page [Visual Hook Guide] tutorial, i'm trying to use those Hooks but the Magic still not happened:
Used hook to show on the Shop Page in the functions.php file:
add_action( 'woocommerce_after_shop_loop_item', 'action_woocommerce_after_shop_loop_item', 20 ); // 1
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 250, 0 ); // 2
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 15 ); // 3
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10); // 4
function woocommerce_template_loop_rating() {
global $product;
$country = $product->get_meta('country');
if ( $country) {
echo '<p class="stateandcity">'. $country .'</p>';
}
}
some of those Hooks hide completely the Price and this is not the goal.
Which hook or filter should i use to make the Magic happens please?
The only one Hook that i have a near result is with the number 2. But as the Picture shows, the Hook brings me a double result, the word two times.
I need to present 5 or more Words in List Format between the product title and the price.
Attached the photo with the result (The Word Brasil shown 2 times):
Anticipated Gratitude for Any Help