1
votes

I am trying to figure out how to replace "woocommerce_page_title" with an ACF field? If there isn't one then it should fall back to "woocommerce_page_title();". I can't seem to find anything super helpful. Your help would be greatly appreciated.

add_filter( 'woocommerce_page_title', 'custom_title' );
function custom_title( $title ) {
    $title = get_field("custom_tag_h1");
    return $title;
}
1

1 Answers

1
votes

For Archives pages taxonomy titles and ACF:

The woocommerce_page_title works for shop page and taxonomy archive pages, so in ACF:

enter image description here

Then in a product category for example (here "Clothing"), you set your custom title:

enter image description here

In the code, you need to get the queried object (the WP_Term object) for the taxonomy archive pages and to set it as following:

add_filter( 'woocommerce_page_title', 'custom_title' );
function custom_title( $page_title ) {
    if ( ! function_exists('get_field') || is_search() )
        return $page_title;

    if ( is_tax() ) {
        $term   = get_queried_object();
        $the_id = $term->taxonomy . '_' . $term->term_id;
    } elseif ( is_shop() ) {
        $the_id = wc_get_page_id( 'shop' );
    }
    return get_field( "custom_tag_h1", $the_id ) ? get_field( "custom_tag_h1", $the_id ) : $page_title;
}

Code goes in function.php file of your active child theme (or active theme). Tested and work.

enter image description here