• Resolved cimot456

    (@cimot456)


    Hi there,

    I got this snippet (below this) to add checkbox custom field which is auto set and it’s working fine.

    add_action( 'woocommerce_product_options_pricing', 'add_custom_field_product_options_pricing' );
    function add_custom_field_product_options_pricing() {
        global $product_object;
    
        echo '</div><div class="options_group">';
    
        $values = $product_object->get_meta('_cutom_meta_key');
    
        woocommerce_wp_checkbox( array( // Checkbox.
            'id'            => '_cutom_meta_key',
            'label'         => __( 'Custom label', 'woocommerce' ),
            'value'         => empty($values) ? 'yes' : $values,
            'description'   => __( 'Enable this to make something.', 'woocommerce' ),
        ) );
    }
    
    // Save quantity setting fields values
    add_action( 'woocommerce_admin_process_product_object', 'save_custom_field_product_options_pricing' );
    function save_custom_field_product_options_pricing( $product ) {
        $product->update_meta_data( '_cutom_meta_key', isset($_POST['_cutom_meta_key']) ? 'yes' : 'no' );
    }

    My question, how to move this checkbox to be on the inventory tab?

    I’ve tried changing :

    this :

    add_action( 'woocommerce_product_options_pricing', 'add_custom_field_product_options_pricing' );

    to this :
    add_action( 'woocommerce_product_options_inventory_product_data', 'add_custom_field_product_options_pricing' );

    and

    this :

    add_action( 'woocommerce_admin_process_product_object', 'save_custom_field_product_options_pricing' );

    to this

    add_action( 'woocommerce_process_product_meta', 'save_custom_field_product_options_pricing' );

    but to no avail.

    Please guide me,

    thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • @cimot456

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.
    
    I can also recommend <a href="https://developer.woocommerce.com/" rel="noopener" target="_blank">the WooCommerce Developer Resources Portal</a> for resources on developing for WooCommerce.
    
    You can also visit the <a href="https://www.facebook.com/groups/advanced.woocommerce/" rel="noopener" target="_blank">WooCommerce Facebook group</a> or the <code>#developers</code> channel of the <a href="https://woocommerce.com/community-slack/" rel="noopener" target="_blank">WooCommerce Community Slack</a>. We're lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.
    Thread Starter cimot456

    (@cimot456)

    Ok thanks for reply

    Hey @cimot456,

    I didn’t check to see if the implementation works at all. If I changed the action to woocommerce_product_options_stock_status that did move the checkbox into the inventory tab for me.

    
    add_action( 'woocommerce_product_options_stock_status', 'add_custom_field_product_options_pricing' );
    

    Is this what you have in mind?

    Thread Starter cimot456

    (@cimot456)

    Hi @3sonsdevelopment

    thanks for your reply.

    I completely forgot to mark that this was resolved.

    I fixed by replacing

    just this line

    add_action( 'woocommerce_product_options_pricing', 'add_custom_field_product_options_pricing' );

    to

    add_action( 'woocommerce_product_options_inventory_product_data', 'add_custom_field_product_options_pricing' );

    And it works as I expected.

    Awesome! Thanks for sharing your solution with the WooCommerce community.

    It’ll be helpful for others facing a similar issue.

    Feel free to create a new topic if you have any further questions.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to change hooks properly?’ is closed to new replies.