Display ACF fields on WooCommerce single product page - woocommerce

I've created a custom field using ACF and I want to show it in my WooCommerce single product page. How can I do that?

You need to find out the hook that represents the place where the ACF field should be displayed, e.g. by using the WooCommerce Visual Hook Guide for the single product page.
example
add_action( 'woocommerce_after_single_product_summary', 'view_acf_field_for_single_product', 10 );
function view_acf_field_for_single_product(){
if (function_exists('the_field')){
the_field('field_name');
}
}
This is adapted from https://support.advancedcustomfields.com/forums/topic/acf-with-woocommerce/.

Related

WordPress ACF custom taxonomy field display

I'm fairly new to WordPress and using the ACF plugin for the first time. I've created a custom post type with custom fields, two of which are of type taxonomy that are tied to custom taxonomies I set up specifically for this post type. That all works great, but I'd like for the custom taxonomies to only show on the post form and not in the right sidebar since that's redundant and confusing for the editors:
Is there anyway to hide them in the sidebar? I already checked categories and tags under the "hide on screen" option for the custom field group, but that didn't seem to make a difference.
Thank you!
add_action( 'admin_menu' , 'wpdocs_remove_post_custom_fields' );
function wpdocs_remove_post_custom_fields() {
remove_meta_box( 'META_BOX_ID' , 'CUSTOM_POST_TYPE' , 'normal' );
}
add in your active themes file -> functions.php
Following parameters:
META_BOX_ID: https://prnt.sc/3TLMZCHCak17
CUSTOM_POST_TYPE: add you custom post type

remove links from woocommerce category using a shortcode

I'm using the shortcode
[product_category category="jacuzzis" columns="3"]
to show some amazon affiliate products on my website. The issue is that I don't want the user going to the product page under my domain but instead going to the amazon affiliate link.
In order to do that I'm trying first eliminating the link on the products. I'm using this code
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 10 );
It should remove the open link tag and the close link tag, but the link is still working after adding the snippet.
Does anyone know why?
You could use woocommerce_after_add_to_cart_quantity hook to add your custom button with ACF field. and just remove 'buy' button with CSS or another hook.

WooCommerce - a hook for featured products shortcode

I'm using the following shortcode to show featured products on my custom page:
[products limit=”6″ columns=”3″ orderby=”rand” visibility=”featured” ]
It works correctly with WooCommerce 3.7.0. The problem I'm having is that I would like to add a quantity input field to each product, before Add to cart button. I already have a function to do this for Shop and Category pages:
add_action( 'woocommerce_after_shop_loop_item', 'taisho_quantity_field', 9 );
Unfortunately for featured products listed via this shortcode it has no effect. Is there any way I can make it work?

WooCommerce Shop page : Customize sorting dropdown to product categories dropdown

I would like to modify the products sorting on the shop page to product categories filter where the user can select the browse the products of categories from there.
I am a rookie in programming. I checked the WooCommerce directory to find the .php file I should work on. I got some clue it is in archive-product.php but I don't see the code which display the sorting dropdown.
Can anyone give me some clue to achieve this ? Or is there any workaround ? Thanks.
I added this in functions.php :
// remove default sorting dropdown
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
// now add the new dropdown
add_action( 'woocommerce_before_shop_loop', 'add_product_category_dropdown' );
function add_product_category_dropdown(){
print '<span class="woocommerce-ordering">'; // So it takes the same position as the default dropdown
the_widget( 'WC_Widget_Product_Categories', 'dropdown=1' );
print '</span>';
}
The reason you wouldn't see the code is that majority of what is generated by Woocommerce is handled by actions and hooks. In easier terms this means Woocommerce creates functions that spits out content and assigns them to different areas of the website.(For more information on Woocommerce actions and hooks, read here - https://docs.woothemes.com/document/introduction-to-hooks-actions-and-filters/ )
I'd recommend using the plugin below. It does exactly what you seem to be asking for and you can avoid having to play in parts you might not be comfortable with yet.
https://wordpress.org/plugins/yith-woocommerce-ajax-navigation/
Most awesome thing is that it's not one of those plugins that force you to get premium to actually get the desired effect.
I just found the solution few days ago. I use the function of WooCommerce product categories widget on the shop page.
This line of code will output the dropdown of product categories:
<?php the_widget( 'WC_Widget_Product_Categories', 'dropdown=1' ); ?>

Products disappearing when adding any category on WooCommerce

Has anyone experienced this before? This is my first time working with WooCommerce.
If I don't add products to a category they will show up in the main shop page as well as have a single product page, as soon as I add a category they will not show up on the main shop page, the category page, or the single product page.
I have not manipulated the wp_query in any way on the page.
I am integrating it into my custom theme which is really barebones, the only thing I have changed is the following in my functions.php file:
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', 'urbantac_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'urbantac_wrapper_end', 10);
function urbantac_wrapper_start() { echo '<div id="products-content" class="products wrap clearfix aligncenter content-container">'; }
function urbantac_wrapper_end() { echo '</div>'; }
I was using another WooCommerce plugin:
http://www.woothemes.com/products/catalog-visibility-options/ to turn off the "store" functionality of WooCommerce and use it as a "catalog"
This adds two settings on the product category pages, and sets defaults to NOT show anyone the content (no idea why this is). The settings are Role Visibility Rules and Location Visibility Rules. It does not mention this anywhere in the documentation for the plugin!
So if you are using this plugin you can no longer create categories directly from a product page, you must first create the category, set the visibility rules, and then create the product.

Resources