• Resolved Gemini23

    (@gemini23)


    Can anyone advise? When I enter a schema code (and the code is validated), when I save the WooCommerce category and the URL refreshes, the code disappears (i.e., it is not saved). What am I doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @gemini23

    Could you please provide a little bit more context on this issue? This extra data will help us determine the best way to help you with our Code Snippets plugin.

    • What exact code are you adding.
    • Describe the process you follow to add this code. Which snippet type are you using for the schema? Are you doing any specific configuration to the snippet?
    • Does this happen to this specific snippet you are adding? So, can you add other snippets and they work as expected?
    Thread Starter Gemini23

    (@gemini23)

    Hi –

    I have realised that the code box is an existing one (not a Snippets one) and one that does work on another website

    The code that I have used to try to add a new Snippets Custom Code Box doesn’t create a new Custom Code box to display…

    Please can you advise the code that would work? It is to add schema for Woocommerce Categories

    Custom Code Box for WooCommerce Categories – Many Thanks

    // Add custom field to WooCommerce category edit screen
    add_action('product_cat_add_form_fields', 'add_custom_schema_field');
    add_action('product_cat_edit_form_fields', 'edit_custom_schema_field');

    // Display custom field on create screen
    function add_custom_schema_field() {
    ?>
    Custom Schema Code

    Enter custom schema or code for this category.
    <?php
    }

    // Display custom field on edit screen
    function edit_custom_schema_field($term) {
    $value = get_term_meta($term->term_id, 'custom_schema_code', true);
    ?>
    Custom Schema Code <?php echo esc_textarea($value); ?>

    Enter custom schema or code for this category.
    <?php
    }

    // Save the custom field
    add_action('created_product_cat', 'save_custom_schema_field');
    add_action('edited_product_cat', 'save_custom_schema_field');

    function save_custom_schema_field($term_id) {
    if (isset($_POST['custom_schema_code'])) {
    update_term_meta($term_id, 'custom_schema_code', sanitize_textarea_field($_POST['custom_schema_code']));
    }
    }


    • This reply was modified 3 months, 1 week ago by Gemini23.

    Hi @gemini23

    We offer our support for issues related to Code Snippets itself, but I cannot provide specific code for you as I’m not an expert on that. I can suggest you to hire a developer. You can also try an AI ChatBot such as chatgpt, if you wish.

    Thanks for understanding.

    Best regards,
    Pau.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.