Support

Account

Home Forums ACF PRO ACF Field default value from another ACF field

Solved

ACF Field default value from another ACF field

  • Hi,

    In our WooCommmerce store we have a custom taxonomy called Brand. Under the Brand taxonomy there is an ACF field called Shipping Time.

    I would like to create another Shipping Timem ACF for WooCommerce products and populate it’s default value from the assigned brands Shipping Time ACF field.

    Is that somehow possible?

  • I assume you mean if you have a taxonomy under WooComm, you are saying that you have a product post type with a new taxonomy of Brand, right? And then each term in that taxonomy (Brand A, Brand B, Brand C) has a field that has a shipping time associated with it. And that you have found some way (there are a few methods) to limit each product to a single brand term. Yes?

    Then I am not sure why you would want to copy this field elsewhere – would you not just use it in the original location? (Having the same data in 2 places just invites it to be wrong somewhere.) You can pull out the information using this:
    https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

    If you really want it in 2 places, you can also use that method to pull out the taxonomy term field value and stuff it into an update_field on the acf/save_post hook.
    https://www.advancedcustomfields.com/resources/acf-save_post/
    See the “applied after save” section and then
    https://www.advancedcustomfields.com/resources/update_field/

  • Thanks for the reply. You are correct, having the information in two places is not smart. I ended up creating a custom shortcode and then using the shortcode to show the shipping time on produt page.

    // ACF Brand Shipping time --> product page
    
    add_action( 'woocommerce_before_single_product', 'boazmarketing_shippingtimeshortcode' );
    function boazmarketing_shippingtimeshortcode() {
    $terms = get_the_terms( $product_id, 'valmistajat' );
    foreach ($terms as $term) {
    $product_cat = $term->term_id;
    }
    $brandid = "valmistajat_". $product_cat;
    $shippingtime = get_field('toimitusaika', $brandid);
    
    return $shippingtime;
    }
    add_shortcode('valmistajan_toimitusaika', 'boazmarketing_shippingtimeshortcode');
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.