Display checkbox in WooCommerce backend, and display content frontend

I am building a site for a client, where i need to display a custom checkbox in the backend product editor, and if the checkbox is checked, then display som content on the frontend.
I have tried this tutorial: http://www.remicorson.com/mastering-woocommerce-products-custom-fields/ and it actually works, but will only display "yes" or "no" depending whether the checkbox is checked or not.

I have looked all over the internet for this, but can't find any answer, so I really hope you can help me.

  • Sajid
    • DEV MAN’s Sidekick

    Hello Mathias,
    Hope you are doing good today :slight_smile:

    You are already on a right track. Use the tutorial above to create the custom check box field.

    On frontend, instead of displaying the field as it is, use that for conditional check and display something else if is checked.

    You can do this by using following code:

    $checked = get_post_meta( get_the_ID(), 'my-field-slug', true );
    if ($checked){
     // Print something here.

    Don't forget to change the "my-field-slug" with your field slug of checkbox.

    Take care and have a nice day :slight_smile:

    Best Regards,
    Sajid - WPMU DEV Support

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.