Skip to content

Instantly share code, notes, and snippets.

@jan-koch
Created November 15, 2018 14:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jan-koch/312cfc891e7118f29a2fc99f13af7612 to your computer and use it in GitHub Desktop.
Save jan-koch/312cfc891e7118f29a2fc99f13af7612 to your computer and use it in GitHub Desktop.
Example for implementing a checkbox as WooCommerce product meta field, in the "General" tab.
<?php
function prefix_add_checkbox() {
$args = array(
'label' => '', // Text in the editor label
'class' => '',
'style' => '',
'wrapper_class' => '', // custom CSS class for styling
'value' => '', // meta_value where the id serves as meta_key
'id' => '', // required, it's the meta_key for storing the value (is checked or not)
'name' => '',
'cbvalue' => '', // "value" attribute for the checkbox
'desc_tip' => '', // true or false, show description directly or as tooltip
'custom_attributes' => '', // array of attributes
'description' => '' // provide something useful here
);
woocommerce_wp_checkbox( $args );
}
add_action( 'woocommerce_product_options_tax', 'prefix_add_checkbox' );
@jan-koch
Copy link
Author

Ja, ist kein Problem. Das kannst du über get_post_meta() laden und dann in der Produkt Admin-Ansicht einbinden. Hier ist ein guter Artikel dazu: https://www.cloudways.com/blog/add-custom-product-fields-woocommerce/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment