I created new ACF in Custom Fields panel and put this code in /woocommerce/templates/single-product/tabs/description.php:
...
<?php the_content(); ?>
//ACF code goes here:
<?php
$term = get_field('category');
if( $term ):
echo 'Category: ' . '' . $term->name . '.';
endif;
?>
It works very good, but if content product is empty, ACF doesn't shown in description tab, i.e. there is no description tab.
How can I make ACF to be shown if product content is empty?
Are you try pass the post ID ?
like
$val= get_field( "test", $ID);
The easiest way is to add space in product content.
Related
I have a coding problem that is just out of my capacity.
I have setup a WooCommerce store with WooCommerce Brands plugin.
I need to be able to "Close" a brand by disabling the "Add to Cart" button. I don't want it to disappear, I only want to disable the button.
I have created a custom field using Advanced Custom Fields and assigned it to the "Brands" taxonomy which is "product_brand".
My custom field is: close_store
Type: Checkbox
Options: Open (Default value) | Closed
When I go to edit a "Brand" I can see my custom field and when I select "Closed" I need a function to then disable the "Add to Cart" buttons.
Is there anyone who can help with this ?
Possible Cross Reference:
Disabling Add to Cart Button for Specific WooCommerce Products
The above looks to do a similar thing but uses "Labels" as the closing criteria and not a custom field. There may be some cross reference here in terms of how the function may need to work.
Hope this helps!
--------------------------------->
UPDATE - Possible Help
Provided by ACF Theme Code Pro Plugin
Taxonomy Term Variables
<?php
// Define taxonomy prefix eg. 'category'
// Use 'term' for all taxonomies
$taxonomy_prefix = 'product_brand';
// Define term ID
// Replace NULL with ID of term to be queried eg '123'
$term_id = NULL;
// Example: Get the term ID in a term archive template
// $term_id = get_queried_object_id();
// Define prefixed term ID
$term_id_prefixed = $taxonomy_prefix .'_'. $term_id;
?>
<?php $close_store_checked_values = get_field( 'close_store', $term_id_prefixed ); ?>
<?php if ( $close_store_checked_values ) : ?>
<?php foreach ( $close_store_checked_values as $close_store_value ): ?>
<?php echo esc_html( $close_store_value ); ?>
<?php endforeach; ?>
<?php endif; ?>
So I'm trying to get a variable to work within an echo do shortcode, however I can't seem to get it working. The goal is to be able to have the client select the brand the backend of the site using ACF instead of hard coding the brand selection.
Here is what I currently have:
<?php $brand_one_ids = get_field( 'brand_one' ); ?>
<?php echo do_shortcode( '[products limit="8" columns="4" class="brand,' . $brand_one_ids . '"]'); ?>
Any advice and fixes would be greatly appreciated!
Nobody could help you on this as you didn't explain in your question, that you:
Have created a product custom taxonomy "Brand".
Are using this answer code to make it work on Woocommerce [products] shortcode
That you want to display those "Brand" products in your home page
Your problem is just a settings problem in ACF. You need to enable those custom fields in your home page, this way:
Then you will get a custom metabox in your home page, with your "Brands" custom fields:
Once filled and saved, this time using the following code on your home, it will work:
<?php if( ! empty( get_field( 'brand_one' ) ) )
echo do_shortcode( '[products limit="8" columns="4" class="brand,' . get_field( 'brand_one' ) . '"]'); ?>
OK so I have inherited a website built by another developer and the code is all over the place. It's a directory site organized by state / city and to make sure that the same city name can appear under different states as unique posts, some funky rewrites and redirects have been implemented.
Long story short, because of these url rewrites, All In One SEO won't work with the custom post type.
I managed a workaround by creating a second header.php for the custom post type and implementing the following:
<?php while ( have_posts() ) : the_post(); ?>
<?php
// get the state name
$state = '';
$states = wp_get_post_terms( get_the_ID(), 'state' );
if( $states ) {
$state = ', ' . strtoupper( $states[0]->description );
}
$city_name = get_the_title();
$title = $city_name . $state;
?>
<title>Cash for Gold Near <?php the_title(); ?> - Find Gold Buyers Near <?php the_title(); ?></title>
<?php endwhile; ?>
It generates the appropriate title tag but then I run into the problem of their being TWO title tags - the custom one and the WP generated one.
Is there a way to get rid of the WP generated title tag (and also the meta description) for a specific custom post type?
Any help is appreciated.
Thanks!
Cynthia
Add a check for the post type where the other title tag is being generated:
if( !is_singular( 'post-type-slug' ) ){
//write normal post title
}
You should replace 'post-type-slug' with the slug used for your post type. You can do the same thing in the other area to only show the title if it IS the right post type:
if( is_singular( 'post-type-slug' ) ){
//write custom post title
}
Change to:
<title>Cash for Gold Near <?php echo $title; ?> - Find Gold Buyers Near <?php echo $title; ?></title>
In my archive page I added the following code:
<p><?php the_field('embed', $term); ?></p>
<p><?php the_field('download_output', $term); ?></p>
On the front-end when i'm on the archive page nothing is displayed. There are values in the field when looking at the WP-Admin taxo page.
Here is the documentation for ACF terms: https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
And the term should be in this format: {$term->taxonomy}_{$term->term_id}
Here is an example to get value from taxonomy term
<?php
$taxonomy = get_query_var('taxonomy');
$termId = get_queried_object()->term_id;
the_field('Your_field_name', $taxonomy . '_' . $termId);
also you can find complete documentation for ACF Here
and you can use get_field if you want to store your value in variable then print it eg: $data = get_field('Your_field_name', $taxonomy . '_' . $termId); then echo the $data wherever you want
If I have custom field on Term custom field on Term Theme, its look like this:
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$myimage = get_field('image', $taxonomy . '_' . $term_id);?>
<?php echo $myimage; ?>
I want to display "image" custom filed on Term posts, I mean any post who use term X get the "image" of X.
How can I do that?
You need to change custom-field with the name of your custom field.
Like this
<?php echo get_post_meta($post->ID, 'term-theme', true); ?>
You can get more information from this WordPress codex page.