my code stock.com

Jamie Cookson

Add tickbox to product data - WooCommerce
by Jamie Cookson

Add Part one to functions.php
Add part two to front end php file

Snippet options

Download: Download snippet as add-tickbox-to-product-data-woocommerce.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?php 
    /* PART ONE */
    
    // Add tickbox to General tab (within product data) under price section 
    function action_woocommerce_product_options_pricing( $array ) { 

		$args = array(
			'id' => 'input_poa', // required
			'wrapper_class' => 'show_if_simple', 
			'label' => __('POA', 'woocommerce' ), // Text in Label
			'description' => __('If this button is ticked, the price will not show on the site.', 'woocommerce' )
		);
		woocommerce_wp_checkbox( $args );

    }; 
    add_action( 'woocommerce_product_options_pricing', 'action_woocommerce_product_options_pricing', 10, 1 ); 

    // Save tickbox generated above ^^
    function woo_add_custom_general_fields_save( $post_id ){

		$woocommerce_checkbox = isset( $_POST['input_poa'] ) ? 'yes' : 'no';
		update_post_meta( $post_id, 'input_poa', $woocommerce_checkbox );

    }
    add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save');
?>

<?php
    /* PART TWO */
        
    // Print data in front-end with one of the following 
	echo get_post_meta( $post->ID, 'input_poa', true );
	echo get_post_meta( get_the_ID(), 'input_poa', true );  
?>




Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.