'_allsame', 'wrapper_class' => 'show_if_variable', 'label' => __('\'All the same\' feature', 'all-the-same-variations-woo' ), 'desc_tip' => 'true', 'description' => __( 'Tick this to enable the \'All the same\' feature', 'all-the-same-variations-woo' ) ) ); // Textbox woocommerce_wp_text_input( array( 'id' => '_allsametext', 'wrapper_class' => 'show_if_variable', 'label' => __('All the same text', 'all-the-same-variations-woo'), 'placeholder' => 'E.g. All the same', 'desc_tip' => 'true', 'description' => __('Text to show on the frontend', 'all-the-same-variations-woo') ) ); } /** * Saving the option fields as above * * @param [integer] $post_id * @return void */ add_action('woocommerce_process_product_meta', 'blz_ats_save_fields_from_prod_editor'); function blz_ats_save_fields_from_prod_editor($post_id) { $atstext = sanitize_text_field($_POST['_allsametext']); $allthesame = isset($_POST['_allsame']) ? 'yes' : 'no'; $allsametext = isset($atstext) ? $atstext : ''; update_post_meta($post_id, '_allsame', $allthesame); update_post_meta($post_id, '_allsametext', $allsametext); } /** * Showing the tickbox on the frontend if product has it ticked * * @return void */ add_action('woocommerce_before_variations_form', 'blz_add_ats_tickbox'); function blz_add_ats_tickbox() { global $product; $prodid = $product->get_id(); $allthesame = get_post_meta($prodid, '_allsame', true); $allthesametext = get_post_meta($prodid, '_allsametext', true); if (!isset($allthesametext) || empty($allthesametext)) { $allthesametext = esc_html( __('All the same', 'all-the-same-variations-woo' ) ); } $selectfirsttext = esc_html( __('Please select first option', 'all-the-same-variations-woo' ) ); if ($allthesame == 'yes') { echo ""; } }