WordPress.org

Ready to get started?Download WordPress

Forums

Trying to learn enabled to disabled. (5 posts)

  1. Kimber254
    Member
    Posted 1 year ago #

    Hi, I'm a bit scared to make changes and need help learning what to look for. This is my first attempt at changing codes in a plug-in without a tutor to work from.

    I bought WooCommerce Custom Product Tabs from terrytsang. It works great but in "add product" page all the tabs I added are default enables and I want default disabled. Right now I have to uncheck all the tabs I don't want and of course it would be quicker to only have to check the ones I want to us depending on products.

    The box I need to change shows up in the advance add product section of the product data.

    I have the php open and found several enable however I think it is one of more of these codes.

    Do I need to change true to false

    $enabled = get_post_meta($post_id, 'enabled_tab_'.$post_id.'_'.$post_index, true);

    if($enabled == 0 && $enabled != "")
    $this->woocommerce_wp_checkbox_input(array('tab' => $post_index, 'id' => $post_index.'_tab_enabled', 'label' => __('Enabled', 'custom_product_tabs'), 'value' => false, 'class' => 'checkbox'));
    else
    $this->woocommerce_wp_checkbox_input(array('tab' => $post_index, 'id' => $post_index.'_tab_enabled', 'label' => __('Enabled', 'custom_product_tabs'), 'value' => true, 'class' => 'checkbox'));

    $this->woocommerce_wp_textarea_input(array('tab' => $post_index, 'id' => $post_index.'_tab', 'label' => __('Content', 'custom_product_tabs'), 'placeholder' => __('Place your content here', 'custom_product_tabs'), 'value' => $tab['custom_tabs'], 'style' => 'width:70%;height:21.5em;'));
    echo '</div>';

    Any advice and if so, can you explain the how or why to me.

  2. Kimber254
    Member
    Posted 1 year ago #

    I've been searching the codex but not sure what is the correct
    page(s) to read. Can someone please point me in the right direction?

    Thank

  3. bcworkz
    Member
    Posted 1 year ago #

    The Codex is usually of little help with plugins.

    I could be wrong, but I think you just need to change the if conditional line to this:
    if($enabled == 0 || $enabled == "")

    The original code read "If the stored value is 0 and there was a value stored, show the enabled option unchecked otherwise show the option as checked." Thus the default when no value is stored is checked.

    My change now reads "If the stored value is 0 OR there was no value stored, show the enabled option unchecked otherwise show the option as checked." Thus the default when no value is stored is unchecked.

    When implementing any kind of hack it's important to keep organized, incremental backups of your changes, and of course a clean copy of the original to revert to if everything goes South. As long as you can revert to original, there's little risk in trying things you're not sure of. Just be sure to test thoroughly before going live. You should have a test installation available so there's no pressure to fix any mistakes.

  4. Kimber254
    Member
    Posted 1 year ago #

    Thank you very much. It at least give me a place to start. I always back up before changing anything. I do have a test wordpress that if I mess up too bad then I can always reinstall.
    Again thank you

  5. Kimber254
    Member
    Posted 1 year ago #

    THANK YOU so much. if($enabled == 0 && $enabled != "1") worked.

Topic Closed

This topic has been closed to new replies.

About this Topic