add a checkbox to woocommerce product advanced options

The reason this doesn’t work is because of the following that you use in your code

'name' => __('Release Required','woocommerce'),

name does not have to be translatable and is applied in the wrong way


Below a working answer. Where I have used woocommerce_admin_process_product_object to save instead of the outdated woocommerce_process_product_meta hook

function add_release_checkbox() {
    // Add checkbox
    $args = array(
        'label' => __( 'Release Form Required','woocommerce' ), // Text in the editor label
        'id' => 'release_req', // required, it's the meta_key for storing the value (is checked or not)
        'desc_tip' => true, // true or false, show description directly or as tooltip
        'description' => __('Tells if a release form is required for this product.','woocommerce') // provide something useful here
    );
    woocommerce_wp_checkbox( $args );
}

add_action( 'woocommerce_product_options_advanced', 'add_release_checkbox' );

// Save Field
function action_woocommerce_admin_process_product_object( $product ) {
    // Isset, yes or no
    $checkbox = isset( $_POST['release_req'] ) ? 'yes' : 'no';

    // Update meta
    $product->update_meta_data( 'release_req', $checkbox );
}
add_action( 'woocommerce_admin_process_product_object', 'action_woocommerce_admin_process_product_object', 10, 1 ); 

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top