Ευχαριστ? πολ?, βρ?κα μια ?κρη που μου δο?λεψε (προσθ?κη στο functions.php) που φα?νεται παρακ?τω:
add_action( ‘woocommerce_after_order_notes’, ‘add_cardholder_name_field’ );
function add_cardholder_name_field( $checkout ) {
echo ” . (‘Cardholder Name’) . ‘
‘; woocommerce_form_field( ‘cardholder_name’, array( ‘type’ => ‘text’, ‘class’ => array(‘cardholder-name-class form-row-wide’), ‘label’ => (‘Cardholder Name’), ‘placeholder’ => __(‘Insert cardholder name as required by Piraeus bank for validation’), ‘required’ => true, ), ‘.’); echo ”;
}
// Save the Cardholder Name field to the order meta
add_action( ‘woocommerce_checkout_update_order_meta’, ‘save_cardholder_name_field’ );
function save_cardholder_name_field( $order_id ) {
if ( ! empty( $_POST[‘cardholder_name’] ) ) {
update_post_meta( $order_id, ‘Cardholder Name’, sanitize_text_field( $_POST[‘cardholder_name’] ) );
}
}
// Validate Cardholder Name field (make it required)
add_action(‘woocommerce_checkout_process’, ‘validate_cardholder_name_field’);
function validate_cardholder_name_field() {
if ( empty( $_POST[‘cardholder_name’] ) ) {
wc_add_notice( __( ‘OPA: Cardholder Name is a mandatory field!’ ), ‘error’ );
}
}
-
This reply was modified 1 month ago by vmarketis.