Support

Account

Forum Replies Created

  • Thanks to all, but no worries, I discovered an alternative way to do this which works great… here is the link.

  • So it turns out that all fields show up if I make sure the “key” is different.

    But now I need to show my tabs, and this code, which should display the new tabs, does not (even when I ensure a tab has content in it):

    if (class_exists('acf') && class_exists('WooCommerce')) {
    	add_filter('woocommerce_product_tabs', function($tabs) {
    		global $post, $product;  // Access to the current product or post
    		
    		$custom_tab_title = get_field('tab_title', $post->ID);
     
    		if (!empty($custom_tab_title)) {
    			$tabs['awp-' . sanitize_title($custom_tab_title)] = [
    				'title' => $custom_tab_title,
    				'callback' => 'awp_custom_woocommerce_tabs',
    				'priority' => 10
    			];
    		}
    		return $tabs;
    	});
     
    	function awp_custom_woocommerce_tabs($key, $tab) {
    		global $post;
     
    		?><h2><?php echo $tab['title']; ?></h2><?php
     
    		$custom_tab_contents = get_field('tab_contents', $post->ID);
    		echo $custom_tab_contents;
    	}
    }

    Any advice is much appreciated!

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