简体   繁体   中英

Show advanced custom field (ACF) if product content is empty

I created new ACF in Custom Fields panel and put this code in /woocommerce/templates/single-product/tabs/description.php :

...
<?php the_content(); ?>

//ACF code goes here:
<?php
$term = get_field('category');
if( $term ):
  echo 'Category: ' . '<a href="' . $get_site_url. '?product_cat=' . $term->slug . '">' . $term->name . '</a>.';
endif;
?>

It works very good, but if content product is empty, ACF doesn't shown in description tab, ie there is no description tab.

How can I make ACF to be shown if product content is empty?

Are you try pass the post ID ? like

$val= get_field( "test", $ID);

最简单的方法是在产品内容中增加空间。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM