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' ) . '"]'); ?>
Related
Hi I'm trying to create a custom plugin that will display the main product image from Woocommerce plugin. I want to use shortcode. How do I go about doing this? This is what I had and it didn't work. I've also found different suggestions. I will share everything below
add_shortcode( 'product_image', 'bbloomer_product_image_shortcode' );
function bbloomer_product_reviews_shortcode() {
return woocommerce_get_product_thumbnail();
}
<?php
$gallery_shortcode = '[gallery id="' .intval($post->$post_parent).'"]';
print apply_filters('the_content', $gallery_shortcode);
?>
These are what I found/were suggested to me before
try this:
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($product_id));
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; ?>
I found the correct hook of where I want the field to show which is below
add_action( 'woocommerce_after_shop_loop', 'after_shop_loop', 1 );
This code works exactly how'd I'd like mine to work but with an ACF text area field. Ideally, I'd like it to show under the pagination. This hook is currently showing above the pagination.
add_action( 'woocommerce_after_shop_loop', 'after_shop_loop', 1 );
function after_shop_loop() {
echo "<div class='best-seller'>
<h3>If you need help or have a question for Customer Service, please visit the <a href='#'>Help Section.</a></h3>
</div";
}
I'd like to create a function to bring in an ACF text area that I've added to the backend for all brands that are coming from WooCommerce taxonomy pages "Brand".
This is what I have so far with no luck. Is there something I'm doing wrong or something special you have to do to get ACF to show on Taxonomy pages? Any help is appreciated. Thanks in advance...
add_action( 'woocommerce_after_shop_loop', 'after_shop_loop', 1 );
function custom_after_shop_loop() {
$brand_content = get_field('brand_bottom');
if( !empty($brand_content) ) {
echo '<div class="brandbottom">' . $brand_content . '</div>';
}
}
Screenshots from my custom field.
Missing "custom_" in the name of your function and you have to get the current taxonomy term. Tested and works
add_action( 'woocommerce_after_shop_loop', 'custom_after_shop_loop', 1 );
function custom_after_shop_loop() {
$term = get_queried_object();
$brand_content = get_field('brand_bottom', $term);
if( !empty($brand_content) ) {
echo '<div class="brandbottom">' . $brand_content . '</div>';
}
}
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.
The code bellow, is to show a custom field I created to customize Woocommerce product category pages.. This code makes the custom field appear "after" the list of products. I need to make this code appear BEFORE the list of products... any hint on what I have to change in this bit of php code to make the custom field show before?
<?php
// Display details on product category archive pages
add_action( 'woocommerce_after_shop_loop', 'wpm_product_cat_archive_add_meta' );
function wpm_product_cat_archive_add_meta() {
$t_id = get_queried_object()->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$term_meta_content = $term_meta['custom_term_meta'];
if ( $term_meta_content != '' ) {
echo '<div class="woo-sc-box normal rounded full">';
echo apply_filters( 'the_content', $term_meta_content );
echo '</div>';
}
}
Thank you, I would really like to understand what makes the code appear after and not before, is the filter? in the last lines?
I found this bit of code at http://www.wpmusketeer.com/add-a-wysiwyg-field-to-woocommerce-product-category-page/
use below action to display custom fields before list of products
add_action('woocommerce_before_shop_loop','wpm_product_cat_archive_add_meta');