Following the request of an SEO agency, I'm trying to recover the content of a field (that I created via ACF in the product categories of WooCommerce) in a function of the functions.php file. I've tried a few tricks found on the net, but nothing works, I can't recover the content.
It's to replace the product category title by another one (the one of the new ACF field) and that this title is only displayed on the category archives of the site (not in the menus and other widgets where the default title is displayed.
Here is the code I did. I get the ID back fine if I display it, I make progress but nothing for $value
<?php
$query_id = get_queried_object_id();
function titre_seo_cat_prod() {
// recupere la valuur d'un post specifique
$value = get_field( 'titre_seo_categorie_de_produit', $query_id );
return $value;
}
?>
Related
I am unable to get the acf text field to display in the woocommerce "Product Tag" admin dashboard.
I have tried the following code, along with many other different variations of looping through the products, retrieving their tags and returning the acf text field but no values are appearing in the columns.
The goal is to customize the Product Tag Admin Dashboard to display the acf text field term. I was able to achieve getting these text field terms in a different portion of code when I created a customize side bar that sections tags by categories that are different from the product categories. I tried that same code for the columns but that isn't working either.
add_filter( 'manage_edit-product_tag_columns', 'tag_category_column_admin', 9999 );
function tag_category_column_admin( $columns ){
$columns['tag_category'] = 'Tag Category';
return $columns;
}
add_action('manage_product_tag_custom_column', 'tag_category_column_admin_content', 10, 2);
function tag_category_column_admin_content($column,$product_id){
$product_tag_terms = wp_get_post_terms($product_id, 'product_tag');
foreach($product_tag_terms as $term){
$category_id = get_field('tag_category' , $term, true);
return $category_id;
}
if($column == 'tag_category'){
echo $category_id;
}
}
I have looked everywhere and cannot seem to find a solution to my problem. Please help!
I have a blog with different custom post types ("books", "interviews", "recipes", "events", etc...). those are all appearing in the home page with same format like a grid. I would like to print in the front end a "label" customized possibly, representing the kind/content of post.
For example:
if the post is a CPT "Book", I want to show in the grid cell "looking for a book?"
if the post is a CPT "Recipe", I want to show on same position, for specific post "hungry?"
etc...
Can you maybe help me in this? I guess I need some PHP code and set it with Elementor, but I am not a developer... :(
Thanks for any help.
Mario.
I have been asked in comment to put a screenshot. this is a fake grid taken from internet (I know, ugly layout), presenting in descending order by date all posts, very different in domain (different custom post types), which I am able to do it. What I need is, depending by Post Type, to add a slogan like "watch the movie" or "hungry?" or "Interview with...", a static string totally dependent by the type of CPT.
fake sample from internet
Further integration to explain the context.
See the current home page of my site: click here
You see two "posts" in a grid (3 columns, published with "post" widget in elementor and a custom skin. This custom skin is linked to a "loop" template created with "ele custom skin". As you see by the pic, you have one post which is a recipe (custom post type "Recipe") and one is a book (custom post type is book). But here I can eventually find also a standard post. Now, when you see the "red dot", I would like to put a word, which is directly dependent by the post type:
if "recipe" --> "Hungry?"
if "book" --> "our book reviews"...
etc...
as a sample I have in this link click here for each loop in the grid, called using "shortcode" widget
[helloworld]
and coded in snippets plugin following portion of php code
function HelloWorldShortcode() {
return '<p>Hello World!</p>';
}
add_shortcode('helloworld', 'HelloWorldShortcode');
Here is the code, from this code shortcode will be [vkh_display_post_tagline]
/**
* Custom shortcode to display the tagline by the post type.
*/
/**
* Custom shortcode to display the tagline by the post type.
*/
function vkh_display_tagline_by_post_type() {
global $post;
if ( ! $post || empty( $post ) ) {
return;
}
// Uncomment the next line for debugging and to know if we're getting post type of not.
// return $post->post_type;
$heading = '';
switch ( $post->post_type ) {
case 'recipe':
$heading = __( 'Hungry?', 'your-text-domain' );
break;
case 'book':
$heading = __( 'Our book reviews', 'your-text-domain' );
break;
// Add more cases following above examples.
default:
// If you have to assign anything default when a case doesn't match
// then write that here.
$heading = '';
break;
}
// When heading is not empty return heading within the html tag.
if ( ! empty( $heading ) ) {
return '<h4 class="post-tagline">' . esc_html( $heading ) . '</h4>';
}
}
add_shortcode( 'vkh_display_post_tagline', 'vkh_display_tagline_by_post_type' );
i want it to be
I want to replace the top Store page name on the wordpress product page with the product name, can anyone help?
example:
i want it to be
How can I do? There is no such setting in the properties of the theme?
Not knowing what theme you are using or how the Shop title is being generated, try adding this code to your functions.php file
add_filter( 'woocommerce_page_title', 'woo_shop_page_title');
function woo_shop_page_title( $page_title ) {
if( 'Shop' == $page_title) {
return the_title();
}
}
This code replaces the page title Shop with the title of the product (post).
I'm using using the WooCommerce plugin for WordPress to display my products. The thing is, when you are viewing the product category (archive), you can see the product name, image and price, but that doesn't really say all that much about exactly what the product is.
What I would like is for some more information to become available when you hover the product images. Something a bit like this.
Would it be possible to retrieve some of the information about the image, that I can enter in the WordPress media libray: title, caption alt text or description?
You can check the webshop here.
EDIT:
I found that editing the content-product.php file in the WooCommerce plugin folder, if I put this:
?>
random text
<?php
somewhere inside the php tags in the <li> section of that file, I could get 'random text' to show either above or below the product image on the product archive page. So, if I could replace that with a function that would retreive for instance the product image caption or some custom field that I can fill out for each product, that would go a long way towards solving the issue.
So, if anyone knows of a function that does this, please share it here.
hello sir just use this plugin
https://wordpress.org/plugins/woocommerce-custom-product-data-fields/
for retrieving any costume fields do like this
Retrieving multiselect value
global $wc_cpdf;
$multiselect = $wc_cpdf->get_value($post->ID, '_mymultiselect');
foreach ($multiselect as $value) {
echo $value;
}
Retrieving image value
global $wc_cpdf;
$image_id = $wc_cpdf->get_value($post->ID, '_myimage');
$size = 'thumbnail';
$image_attachment = wp_get_attachment_image($image_id, $size);
echo $image_attachment;
}
I recently did this with a website for a client. I changed the hover text for each product from "Add to Cart" to the product short description. Here is my code:
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' ); // 2.1 +
function woo_archive_custom_cart_button_text() {
//get the product object
global $product;
$id = $product->get_id();
$descript = $product->get_short_description();
//take out html from description
$descript1 = strip_tags($descript);
//shorten description length to fit the product image box
if (strlen($descript1) > 100){
$descript1 = substr($descript1, 0, 99) . '...';
}
return __( $descript1, 'woocommerce' );
}
In WooCommerce, I have created an attribute "Brand", and added some terms, like "Brand One", "Brand Two" etc..
I want to add an image for each term.
Right now there is no option to add image in attribute terms.
Please tell me how to add image in attribute terms.
An admin link is like this:
.../wp-admin/edit-tags.php?taxonomy=pa_brand&post_type=product'
WooCommerce stores product attributes outside of the usual taxonomy table, so you'll need to go with something more WC-specific. Try the Variation Swatches and Photos extension.
UPDATE: You can use the Taxonomy Images plugin but you have to make a minor alteration. By default the plugin only displays taxonomies that are set to display in the admin area (i.e. the show_ui value is set to true). WooCommerce hides the product attribute taxonomies by default, so the plugin will not display them in the settings screen. You can change this behaviour by commenting out/deleting lines 402-402 of taxonomy-images.php:
if ( ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) )
continue
Removing these lines will allow he plugin to display all taxonomies, regardless of whether they are hidden or not.
Props to #helgatheviking for suggesting that plugin in the first place
With the "Variation Swatches" plugin (see the answer by #Dre), everything works smoothly, and getting the image is as easy as this:
$swatch_term = new WC_Swatch_Term( 'swatches_id', $term_id, $taxonomy, false,
'swatches_image_size' );
$html = '<img src="' . $swatch_term->thumbnail_src . '" alt=""/>';
The "Taxonomy Images" has not been updated since WP 3.6.1...
Technically a WooCommerce "attribute" is just a WordPress Custom Taxonomy. Therefore I would try something like the Taxonomy Images plugin.
"Variation Swatches and Photos extension" plugin is premium and no body would like to purchase that to serve such a purpose as getting an icon image for a brand.
The "Taxonomy Images" has not been updated since WP 3.6.1...
What I came up with is Category and Taxonomy Image and that does the job.
Here's how you can get the image URL:
if (function_exists('get_wp_term_image'))
{
$meta_image = get_wp_term_image($term_id);
//It will give category/term image url
}
echo $meta_image; // category/term image url
I've fixed this issue. Actually i was not passing the right value in taxonomy. I was using variation swatches plugin so was not know which value to pass for taxonomy. below is the working code. I was trying to fetch "brands" attributes list with images.
$attribute_taxonomies = wc_get_attribute_taxonomies();
$taxonomy_terms = array();
if ($attribute_taxonomies) :
foreach ($attribute_taxonomies as $tax) :
if (taxonomy_exists(wc_attribute_taxonomy_name($tax->attribute_name))) :
if($tax->attribute_name=="brands"){
$taxonomy_terms[$tax->attribute_name] = get_terms(wc_attribute_taxonomy_name($tax->attribute_name), 'number=6&orderby=name&hide_empty=1');
}
endif;
endforeach;
endif;
foreach ($taxonomy_terms as $item) :
foreach($item as $child):
//print_r($child);
$thumbnail_id = get_woocommerce_term_meta( $child->term_id, 'product_pa_brands', true );
$textureImg = wp_get_attachment_image_src( $thumbnail_id );
//we are getting image in $textureImg[0]
}
endforeach;
endforeach;