ACF Value not updating as per frontend submit data - woocommerce

I am using ACF and Gravity Form with Post Creation Addon.
In GF i used radio fields, select fields to take input from frontend and save data into ACF select field or radio fields,
All data is saving correctly except the radio, select dropdowns.
When checking Post Meta all data is exactly showing which is entered in frontend but ACF field isn't updating.
I used Below Code as well but the correct ACF option isn;t showing.
function occassion_save( $post_id, $feed, $entry, $form ) {
// Checkboxes field id.
$field_id = 1;
// Get field object.
$field = GFAPI::get_field( $form, $field_id );
if ( $field->type == 'radio' ) {
// Get a comma separated list of checkboxes checked
$checked = $field->get_value_export( $entry );
// Convert to array.
$values = explode( ', ', $checked );
}
// Replace my_custom_field_key with your custom field meta key.
update_post_meta( $post_id, 'occassion', $values );
}
[![Gravity Form and Post Creation Addon, Campaign SUbmission][1]][1]
[![ACF Field in Backend woo product][2]][2]
[![Meta Data showing Correct Data][3]][3]
[1]: https://i.stack.imgur.com/NM3wz.png
[2]: https://i.stack.imgur.com/zYhBj.png
[3]: https://i.stack.imgur.com/xQMY9.png
How can i update ACF field exactly as my meta data value...

Related

changing the display location of custom product field on a variable product page

i added a custom field to a variable product and displayed it on the front single product page with the help of an answer here
https://stackoverflow.com/a/55774613/14382875
by default the custom field is displayed on the front page above the add to cart button. but i want to move the custom field from there to right above the product meta data or the sku field in variable product. i was able to do this in simple product via hooks but the variable product code doesn't seem to be using any hook or i am missing something.
the code i used to display the variable product on front is this
function vp_variation_display_commodity_code( $data, $product, $variation ) {
if( $value = $variation->get_meta( 'jk_mpn' ) ) {
$data['price_html'] .= '<p class="vp-ccode"><strong>' . __("Manifacturer Part #", "woocommerce") .
': </strong>'.esc_html( $value ).'</small></p>';
}
return $data;
}```

Pass dynamic post id to cf7 form

I am using https://wordpress.org/plugins/tangible-loops-and-logic/ to show a list of posts. Each post also contains a Contact Form 7 form. That form has a dropdown which should be populated by an acf repeater field that is attached to each post.
My issue is that in order to retrieve the correct values I need to get the correct post id for each post. I know I can create a dynamic field in cf7 to show the post ID but I'm not really sure how I can pass that around so that I can retrieve the correct repeater.
My loop (simplified):
<Loop type=seminar count=3>
<Field title />
<div class="seminarContent">
...
</div>
[contact-form-7 id="619" title="Seminar"]
</Loop>
The select field of my form:
[select termine data:gigs]
my current code to retrieve the post ID which would work if it was on the single post page, but unfortunately not within a loop showing all posts on the same page as discussed here https://stackoverflow.com/a/71840727/6118046:
add_filter( 'wpcf7_form_tag_data_option', 'dd_filter_form_tag_data', 10, 3 );
function dd_filter_form_tag_data( $n, $options, $args ) {
// Get the current form.
$cf7 = wpcf7_get_current_contact_form();
// Get the form unit tag.
$unit_tag = $cf7->unit_tag();
// Turn the string into an array.
$tag_array = explode( '-', $unit_tag );
// The 3rd item in the array will be the page id.
$post_id = substr( $tag_array[2], 1 );
if ( in_array( 'gigs', $options, true ) ) {
$gigs = array();
if ( have_rows( 'termine', $post_id ) ) :
while ( have_rows( 'termine', $post_id ) ) :
the_row();
$gigs[] = get_sub_field( 'termin' );
endwhile;
endif;
$n = array_merge( (array) $n, $gigs );
}
return $n;
}
Seems to work if I use the previous version of the plugin, called "custom content shortcode". Then add a custom field (text) to my post in which I paste the cf7 shortcode (same for all posts) and then call the field in the frontend. Dropdown gets properly filled that way.

Can you edit WordPress custom post types directly from the archive list page?

Is there a way to edit WordPress custom post types directly from the archive list page. For example, you would use the "list" view to edit the posts and pages in that custom post type, including all o the custom fields.
Option 1: Using a plugin
If you're using ACF, the easiest way to do this would be with ACF Quick Edit Fields plugin.
Option 2: Using code
If you don't want to use a plugin, you need to:
Add columns to the list page
Get the fields and display it in these columns
You can add the following code to your theme's functions.php:
Add columns for the data you want displayed in the list
// Replace 'cpt_name' with your custom post type name
function add_custom_columns ( $columns ) {
$columns['custom_field_1'] = __( 'Custom Field 1 Column Name' );
$columns['custom_field_2'] = __( 'Custom Field 2 Column Name' );
return $columns;
}
add_filter ( 'manage_cpt_name_posts_columns', 'add_custom_columns' );
Get the fields and display it in the columns
function display_cf_columns ( $column, $post_id ) {
switch ( $column ) {
case 'custom_field_1':
echo get_post_meta ( $post_id, 'post_meta_1', true );
break;
case 'custom_field_2':
echo get_post_meta ( $post_id, 'post_meta_1', true );
break;
}
}
add_action ( 'manage_cpt_name_posts_custom_column', 'display_cf_columns', 10, 2 );

How to update Order meta data, from a WooCommerce Action

I'm trying to add some custom meta_data to a WooCommerce Order, by running a Order action.
Here is my code:
function custom_add_order_actions( $actions ){
global $theorder;
$actions['my_custom_action'] = 'My custom action';
return $actions;
}
add_action( 'woocommerce_order_actions', 'custom_add_order_actions' );
function custom_add_single_action( $order ){
// Non of these change anything on the order
$order->set_billing_first_name( 'A new test name' );
$order->update_post_meta( 'a_test_field', 'Test field value' );
update_post_meta( $order->get_id(), 'a_test_field', 'Some other value' );
// $order->save(); // I even tried adding this as well, but it doesn't change anything.
}
add_action( 'woocommerce_order_action_my_custom_action', 'custom_add_single_action' );
How do I change the order (or specifically, post_meta fields for an order) from inside an action?
A example
Imagine that I add a post_meta field, with the field name (key): a_test_field.
It's currently an ACF-field, but it's the same for regular WordPress custom fields.
If I change the value of the field and press 'Update', then the value changes:
So far so good. Now the value of the field is 'Foobar'.
What's wierd is that even if I do this:
add_action( 'woocommerce_order_action_my_custom_action', 'custom_add_single_action' );
function custom_add_single_action( $order ){
update_post_meta( $order->get_id(), 'a_test_field', 'A new value' );
die(); // This die is vital, to make the change in the database.
}
Then I can see the value change in the database to 'A new value'.
But if I just do this:
add_action( 'woocommerce_order_action_my_custom_action', 'custom_add_single_action' );
function custom_add_single_action( $order ){
$order->update_post_meta( 'a_test_field', 'A new value' );
// No die(); here...
}
Then the value remains 'Foobar' in the database.
Sorry but the following lightly revisited code works (Selecting the action and click on the button arrow):
add_action( 'woocommerce_order_actions', 'add_custom_order_action' );
function add_custom_order_action( $actions ){
$actions['my_custom_action'] = __('My custom action', 'WooCommerce');
return $actions;
}
add_action( 'woocommerce_order_action_my_custom_action', 'triggered_custom_order_action' );
function triggered_custom_order_action( $order ){
$order->update_meta_data( '_test_1_custom_field', 'AAFFBB9977' );
$order->save();
update_post_meta( $order->get_id(), '_test_2_custom_field', 'Some other value' );
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Note: Order actions are mostly used for some other things than what you are trying to do.
Now when using a meta box with an input field (as you are showing), on submit, you should save that field value using the action hook save_post_shop_order like in those related threads:
Metabox with multi checkbox in WooCommerce admin single orders
Dynamic custom order numbers based on payment method
Metabox with multiple custom fields for WooCommerce admin order pages

Advanced Custom Fields repeater delete_post_meta hooks passing the wrong meta

I'm trying to run some additional functions when updating and deleting ACF custom post meta, ACF version 4.3.8. The ACF field type is a repeater with several rows. When I delete one of these rows, I'm getting the wrong $meta_key passed to my hook:
<?php
class My_Consultant_Save_Post {
function __construct() {
add_action( 'delete_post_meta', array ( $this, 'delete_consultant_meta_connections'), 10, 4 );
}
public function delete_consultant_meta_connections( $meta_id, $post_id, $meta_key, $_meta_value ) {
echo 'post_id';
var_dump($post_id);
echo 'meta_key';
var_dump($meta_key);
echo 'current value of meta, before deleting';
$current = get_post_meta($post_id, $meta_key);
var_dump($current);
die;
}
}
$my_consultant_update = new My_Consultant_Save_Post();
see delete_postmeta function, and the action delete_post_meta
actually it appears to be passing the $meta_key of the last row entry I have in the field group's repeater field, and definitely not one that I deleted from the front-end post editor's acf remove row button.
Any ideas why the hook is not returning the meta_key of the actual meta I tried to delete?

Resources