Show Advanced custom field in wpallexport - wordpress

I wanted to export a Advanced custom field and therefore I used the Function Editor in wpallexport, but nothing is showing up.
I created a ACF field for the product in woocommerce (wirtschaftlicher_eigentumer), I tried to get it over the product_id but nothing appears.
function wirtschaftlicher_eigen ($product_id) {
if ( ! empty($product_id) ) {
return get_field('wirtschaftlicher_eigentumer', 'product_' . $product_id);
}
}
Want to get the field but instead it's empty.

You need to change
return get_field('wirtschaftlicher_eigentumer', 'product_' . $product_id);
To
return get_field('wirtschaftlicher_eigentumer', $product_id);
The $product_id will return the current post id.

Related

Woocommerce - Remove fields from woocommerce_form_field including validation

I am trying to customise the Woocommerce myaccount page, in particular the edit address page.
I want to display both the shipping + billing address forms on a single page. Ideally, in a single form with a one save button. I also need to remove a lot of the fields, so that it's a much simpler form of just an address (no name, company, etc).
I have implemented the code found on This Answer. It works nicely in that it shows both forms. However, I cannot remove the fields from the forms. If I try code like this:
add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
add_filter( 'woocommerce_shipping_fields' , 'custom_override_shipping_fields' );
function custom_override_billing_fields( $fields ) {
unset($fields['billing_country']);
unset($fields['billing_company']);
unset($fields['billing_first_name']);
unset($fields['billing_last_name']);
unset($fields['billing_phone']);
unset($fields['billing_email']);
return $fields;
}
function custom_override_shipping_fields( $fields ) {
unset($fields['shipping_country']);
unset($fields['shipping_company']);
unset($fields['shipping_first_name']);
unset($fields['shipping_last_name']);
return $fields;
}
It doesn't work, the fields are no longer shown but the form does not save on click... it just redirects to /my-account/edit-address/billing/ - and doesn't save. (the same form shown on this page doesn't save either).
I've also tried:
foreach ( $billing_fields as $key => $field ) :
if($key != 'billing_first_name' && $key != 'billing_last_name') :
woocommerce_form_field( $key, $field, $userMeta[$key][0] );
endif;
endforeach;
This removes the field from displaying, BUT the validation still exists - and any filter code I add to functions using
woocommerce_checkout_fields to remove the validation doesn't seem to affect this form at all.
Is there a way to either:
Remove fields from this form generated by woocommerce_form_field including the validation?
Create a custom form that allows me to set the input fields manually in the code, and update any fields that are there, ignoring the validation from Woocommerce completely?
This should work 100%. You need to state whether the fields you are removing is from billing or shipping and this is done by adding the ['billing'] or ['shipping'], whichever it is.
After this, adding the function directly to woocommerce_checkout_fields will apply both for billing and shipping.
For phone and company fields you can disable it in admin panel itself, do it.
Edit: And yes, all validation that was involved with the fields in the past will be removed. You can then apply any validation you need.
add_filter( 'woocommerce_checkout_fields' , 'brandimagemarketer_remove_billing_fields_checkout' );
function brandimagemarketer_remove_billing_fields_checkout( $fields ) {
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_email']);
unset($fields['shipping']['shipping_country']);
unset($fields['shipping']['shipping_first_name']);
unset($fields['shipping']['shipping_last_name']);
unset($fields['shipping']['shipping_email']);
return $fields;
}

How to override the category template on the /shop/ page when showing filtered products?

I already created a function that will filter products using URL parameters and display them on the /shop/ page. That works fine.
But, that only works if the products template is set on the WooCommerce /shop/ page.
In my case the requirement is to have the category list set as default template on the /shop/ page. That means I need to override that template and show the filtered product list, when I run a product query with URL parameters.
(eg. example.com/shop/?param1=foo&param2=bar)
I tried following code (and some iterations), but I'm stuck and have no clue how to override the default template when a product filter is applied:
add_filter( 'woocommerce_locate_template', [$this, 'my_include_template_function'], 10, 3 );
public function my_change_template_function($template, $template_name, $template_path)
{
if (!empty($_GET['param1']) && is_shop() && $template_name == 'content-product_cat.php') {
return wc_get_template_part('content', 'product');
} else {
return $template;
}
}
So the source of the categories loop is added in to the loop start [via a filter][1]
add_filter( 'woocommerce_product_loop_start', 'woocommerce_maybe_show_product_subcategories' );
and the woocommerce_maybe_short_product_subcategories() function changes the output based on the:
$display_type = woocommerce_get_loop_display_mode();
However, the woocommerce_get_loop_display_mode() result isn't filterable directly.
But it relies on some values from get_option() (since the setting is in the customizer) and get_option() is filterable via option_$option
So a potential way to tell WooCommerce not to display the categories when you have a particular $_GET parameter, you could filter the shop display mode option to be products when that parameter is detected in the URL. Like this:
/**
* Filter shop display type.
*
* #param string $value - 'products' | 'subcategories' | 'both'
* #return string
*/
function kia_woocommerce_shop_page_display( $value ) {
if ( ! empty( $_GET['param1'] ) {
$value = 'products';
}
return $value;
}
add_filter( 'option_woocommerce_shop_page_display', 'kia_woocommerce_shop_page_display' );

Advanced Custom Fields Default Values Based On Current User

How to set product field value based on current user's display name in ACF plugin?
Following acf/load_field[acf/load_field filter documentation][1] I tried adding this to my functions.php:
function acf_load_user_display_name( $field ){ $user = wp_get_current_user(); $display_name = $user->display_name; return $user->display_name; } // acf/load_field - default for product_display_name field add_filter('acf/load_field/name=product_display_name', 'acf_load_user_display_name');
This code makes a bug on the edit-product page and ACF-edit-field groups, and the custom field "product_display_name" is still blank on the product page.
[1]: https://www.advancedcustomfields.com/resources/acf-load_field/

Woocommerce choose grid or list view for each category

I want the possibility to choose between grid and list view for each Woocommerce category. I have found this plugin: https://nl.wordpress.org/plugins/woocommerce-grid-list-toggle/
However, the plugin is meant for the shopper to choose whether to display items in grid view or list view. What I truly want is the ability to assign a view for each category in the back-end.
Example:
Category A is displayed as grid
Category B is displayed as list
Breaking my head over this.
Similar to this question you need to filter template_include. You need to call your custom archive template archive-list-view.php and save it in your theme's woocommerce folder. Obviously, you can name it anything you like, you will just have to adjust the code below to match.
Folder structure:
/theme-folder/functions.php
/theme-folder/woocommerce/archive-list-view.php
On the template_include filter we will check if we are on the term archive for the nussmylch product category. If so, we'll look for and supply the new template. Otherwise, the standard template is used.
EDIT: incorrect WooCommerce function is_product_taxonomy() was used. is_product_category() is needed to check for a specific category.
add_filter( 'template_include', 'so_33615903_custom_category_template', 20 );
function so_33615903_custom_category_template( $template ) {
// check you are on the taxonomy archive for specific category
if ( is_product_category( 'nussmylch' ) ) {
$new_template = locate_template( array( 'woocommerce/archive-list-view.php' ) );
if ( '' != $new_template ) {
$template = $new_template ;
}
}
return $template;
}
Working Example

woo_breadcrumbs function and custom-post-type

I am using the woo_breadcrumbs function and need to insert the name of the curent custom post type. Currently it is showing the home page + category, Home -> Category . Is there a simple way to call the name of the current Custom-Post-Type and insert it between home and category? The function inside the admin-fuction.php file in functions folder.
Thanks!!
So far I have found the following, hope it helps. This is written to be specific to a single taxonomy:
add_filter( 'woo_breadcrumbs_args', 'woo_video_filter_breadcrumbs_args', 10 );
if ( ! function_exists( 'woo_video_filter_breadcrumbs_args' ) ) {
function woo_video_filter_breadcrumbs_args( $args ) {
$args['singular_video_taxonomy'] = 'videos';
return $args;
}
}

Resources