'checkbox', 'class' => array('form-row-age-policy'), 'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox', 'woocommerce-age-check'), 'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'), 'required' => true, 'label' => $checkText )); } } // -------------------------------------------------------------------------------- // Show notice if customer does not tick the box add_action( 'woocommerce_checkout_process', 'bcWOAG_not_approved_age' ); function bcWOAG_not_approved_age() { if(get_option( 'woocommerce_betawooage_checkbox' )=='yes'){ if ( ! (int) isset( $_POST['age_policy'] ) ) { if(get_option( 'woocommerce_betawooage_multilanguage' )=='yes'){ $failText = __( "Please confirm that you are 18 years or older by ticking the box!", 'betawooage' ); }else{ $failText = get_option( 'woocommerce_betawooage_failuremessage' ); } wc_add_notice( $failText, 'error' ); } } } // -------------------------------------------------------------------------------- // Add the menu items to the Woo settings page add_filter( 'woocommerce_general_settings', 'bcWOAG_form_wpadmin' ); function bcWOAG_form_wpadmin( $settings ) { $newsettings = array(); foreach ( $settings as $section ) { // at the bottom of the General Options section if ( isset( $section['id'] ) && 'general_options' == $section['id'] && isset( $section['type'] ) && 'sectionend' == $section['type'] ) { $newsettings[] = array( 'name' => __( 'Enable age checkbox', 'betawooage' ), 'id' => 'woocommerce_betawooage_checkbox', 'type' => 'checkbox', 'css' => '', 'std' => 1, // WC < 2.0 'default' => 1, // WC >= 2.0 'desc' => __( "Display a mandatory checkbox.", 'betawooage' ), ); $newsettings[] = array( 'name' => __( 'Multilanguage age checkbox', 'betawooage' ), 'id' => 'woocommerce_betawooage_multilanguage', 'type' => 'checkbox', 'css' => '', 'std' => 1, // WC < 2.0 'default' => 1, // WC >= 2.0 'desc' => __( "Refer to the known translations of this plugin or create your own by using another plugin.", 'betawooage' ), ); if(get_option( 'woocommerce_betawooage_multilanguage' )=='no' OR get_option( 'woocommerce_betawooage_multilanguage' )==''){ $newsettings[] = array( 'name' => __( 'Checkbox message', 'betawooage' ), 'id' => 'woocommerce_betawooage_checkboxemessage', 'type' => 'textarea', 'css' => 'min-width:300px; min-height:100px;', 'std' => "You have to be 18 years or older to order products at this webshop. By checking this box you confirm that you are 18 years or older.", // WC < 2.0 'default' => "You have to be 18 years or older to order products at this webshop. By checking this box you confirm that you are 18 years or older.", // WC >= 2.0 'desc' => __( "Display the text people see before ticking the box.", 'betawooage' ), ); $newsettings[] = array( 'name' => __( 'Failure message', 'betawooage' ), 'id' => 'woocommerce_betawooage_failuremessage', 'type' => 'textarea', 'css' => 'min-width:300px; min-height:100px;', 'std' => "Please confirm that you are 18 years or older by ticking the box.", // WC < 2.0 'default' => "Please confirm that you are 18 years or older by ticking the box.", // WC >= 2.0 'desc' => __( "Display message to people that don't tick the box.", 'betawooage' ), ); } } $newsettings[] = $section; } return $newsettings; } /* make the plugin page row better */ function bcWOAG_pl_links( $links ) { $links = array_merge( array( '' . __( 'Patreon', 'betawooage' ) . '' ), $links ); return $links; } add_action( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'bcWOAG_pl_links' ); ?>