Support

Account

Forum Replies Created

  • I’m looking for this as well. I found a solution here: https://stackoverflow.com/a/20293486/1766219

    Note, that there is typo on that solution, which I have corrected in below-written solution:

    
    global $wpdb; // (this is required when are you inside the function)
    
    $values = $wpdb->get_results("SELECT DISTINCT meta_value FROM $wpdb->postmeta pm, $wpdb->posts p WHERE meta_key  = 'NAME_OF_THE_FIELD_YOURE_AFTER' and pm.post_id=p.ID  and p.post_type='CUSTOM_POST_TYPE_NAME' ",ARRAY_A);
    
    print_r($values);
    
  • I solved it myself.
    The solution is to add this line:

    `
    wp_safe_redirect( admin_url(‘/post.php?post=’. $post_id .’&action=edit’) );
    `

    after the update_post_meta().

    I think that WooCommerce overwrites the meta-fields as a sort of ‘very-last-thing’, when running those actions.

  • I think I’m having this problem as well. It’s really wierd.

    I’m building a custom WooCommerce-action that does a bunch of stuff for the given order. I initiate the action, by adding this to the functions.php-file:

    
    function custom_add_order_action( $actions ){
      global $theorder;
      $actions['custom_thing'] = 'My own custom action';
      return $actions;
    }
    add_action( 'woocommerce_order_actions', 'custom_add_order_action' );
    
    add_action( 'woocommerce_order_action_custom_thing', 'custom_action_content' );
    function custom_action_content( $order ){
      $my_class = new WcActionCustomActionClass( $order );
    }
    

    … and inside WcActionCustomActionClass a bunch of things happen.

    One of which should be to update the ACF-fields for the WooCommerce order. Let’s say that the order_id is 12345.

    Regardless of what I do, then I can’t get it to update _any_ of the fields, when I run update_field() inside my class, _unless_ if I write die()' afterwards(?!).

    So if I do this:

    
    update_field( 'test', 'some value', 12345 );
    

    and run the action, then the value of the test-field hasn’t changed.

    But if do this:

    
    update_field( 'test', 'some value', 12345 );
    die();
    

    … and then check it in another browser-window, then the value _does_ change. Really wierd!

    ————–

    ### Solution attempts

    **1. New field**

    I tried creating a new field and trying to update that. Exactly the same bug as described above.

    **2. Updating the field elsewhere**

    I tried updating the field in the init-hook, ensuring that my code actually works:

    
    function test_init(){
      update_field( 'test', 'another test value', 12345 );
    }
    add_action( 'init', 'test_init' );
    

    This updates the field (as it should).

    **3. Updating the field before my class is initialized**

    I tried changing my code, so it looks like this instead:

    
    ...
    function custom_action_content( $order ){
      update_field( 'test', 'another another test value', 12345 );
      $my_class = new WcActionCustomActionClass( $order );
    }
    

    **4. Using the field_key**

    I tried using the field key, like this:

    
    ...
    function custom_action_content( $order ){
      update_field( 'field_603f667437ba9', 'another another another test value', 12345 );
      $my_class = new WcActionCustomActionClass( $order );
    }
    

    … Same thing. No change.

    And again. If I do this:

    
    ...
    function custom_action_content( $order ){
      update_field( 'field_603f667437ba9', 'another another another test value', 12345 );
      die();
      $my_class = new WcActionCustomActionClass( $order );
    }
    

    … and open the order in a new window, then the value updates(?!). Omg…

    **5. get_the_object**

    Inside my class, I tried getting the field object, ensuring that it was accessible. So I did this:

    
    $field = get_field_object( 'field_603f667437ba9' );
    vardump( $field );
    die();
    

    and it returns an array of the field:

    
    array (
      "ID" => 48617
      "key" => "field_603f667437ba9"
      "label" => "Test"
      "name" => "test"
      "prefix" => "acf"
      "type" => "text"
    ...
    

    So it _is_ accessible! Hmm…

    **6. Moving the function up to fire earlier**

    I figured, that maybe something ‘got in the way’ of the ACF-function firing, so by moving it up to be the first thing that runs during that action, then maybe that could make a change.

    … But it was the same result: No change, unless I made it die() just after.

    **7. Moving the function, making it fire later**

    So that means doing this:

    
    ...
    function custom_action_content( $order ){
      $my_class = new WcActionCustomActionClass( $order );
      update_field( 'field_603f667437ba9', 'another another another test value', 12345 );
    }
    

    … Same thing. Doesn’t change, unless I write die(); after.

    **8. Clear cache and restart Apache/Nginx**

    Didn’t change anything.

    **9. Try using update_post_meta() instead**

    Same result.

    This doesn’t change anything:

    
    update_post_meta( 12345, 'test', 'Another another another... value' );
    

    This make the value change:

    
    update_post_meta( 12345, 'test', 'Another another another... value' );
    die();
    

  • @yitwail
    ‘s answers solved it for me. Removing the variable-name $acf made the error go again. My error was:

    Fatal error: Uncaught Error: Call to a member function is_path_valid() on array in '/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/api/api-helpers.php:296'

    and

    Fatal error: Uncaught Error: Call to a member function init() on array in '/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/api/api-helpers.php:296'

  • The link above ( http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/ ) gives a 404. Based on the URL, I would really like to read that article (and I can’t find it, using Google). Any help?

Viewing 5 posts - 1 through 5 (of 5 total)