admin管理员组

文章数量:1387429

i have a question if i wanted to hide the title if nothing is entered how can i achive this with this fuction i would be greatful for any help

add_action( 'woocommerce_single_product_summary', 'my_custom_fuction');

function my_custom_fuction() { echo 'Pack Quantity: ' . get_field('pack_quantity'); echo'
'; echo 'items per: ' . get_field('per_pack');

with pack quantity, items per being my title

i have a question if i wanted to hide the title if nothing is entered how can i achive this with this fuction i would be greatful for any help

add_action( 'woocommerce_single_product_summary', 'my_custom_fuction');

function my_custom_fuction() { echo 'Pack Quantity: ' . get_field('pack_quantity'); echo'
'; echo 'items per: ' . get_field('per_pack');

with pack quantity, items per being my title

Share Improve this question edited Apr 13, 2020 at 16:55 LORDY'S GAMING CHANNEL asked Apr 13, 2020 at 14:59 LORDY'S GAMING CHANNELLORDY'S GAMING CHANNEL 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

You can check if the get_field() comes up empty by doing

if ( get_field('pack_quantity') ) {
     //Your code
}

So something like this should work if you just need to check one of the fields.

add_action( 'woocommerce_single_product_summary', 'my_custom_fuction');

function my_custom_fuction() {

    if ( get_field('pack_quantity') ) { //Change this for which one you need to check
        echo 'Pack Quantity: ' . get_field('pack_quantity');
        echo''; 
        echo 'items per: ' . get_field('per_pack');
    }
}

https://www.advancedcustomfields/resources/hiding-empty-fields/

本文标签: woocommerce offtopicHelp with with my function for wordpress