Last active
September 5, 2023 00:34
-
-
Save jasperf/767efe5982e5fc6eb42f16a20679097e to your computer and use it in GitHub Desktop.
Append an ACF field after WooCommerce Product title for specific pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This solutions uses WooCommerce's built in `woocommerce_after_shop_loop_item_title` | |
* action to load the ACF field after the shop loop item title | |
* | |
* Much less memory intense than initial solution than direct title manipulation | |
*/ | |
function add_custom_text_after_product_title_single() { | |
if ( ( is_front_page() || is_shop() ) ) { | |
// Get the value of the ACF field (replace 'your_acf_field_name' with the actual field name) | |
$acf_field_value = get_field( 'kleding_prijs_vanaf' ); | |
if ($acf_field_value) { | |
echo '<div class="acf-field-content">' . esc_html($acf_field_value) . '</div>'; | |
} | |
} | |
} | |
add_action('woocommerce_after_shop_loop_item_title', 'add_custom_text_after_product_title_single', 15); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Much less memory intense than initial solution. This solutions uses WooCommerce's built in `woocommerce_after_shop_loop_item_title action to load the ACF field after the shop loop item title: