تابع ووکامرسی woocommerce_form_field نمایش فرم آدرس و تسویه حساب

تابع ووکامرسی woocommerce_form_field نمایش فرم آدرس و تسویه حساب

تابع ووکامرسی woocommerce_form_field – نمایش فرم آدرس و تسویه حساب

Syntax – سینتکس

woocommerce_form_field( (string) $key, (mixed) $args, (null) $value = null ); 

Parameters – پارامتر ها (3)

  • 1- $key (string)
  • 2- $args (mixed)
  • 3- $value (null)

Usage – نحوه استفاده

if ( !function_exists( 'woocommerce_form_field' ) ) { 
    require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
} 
  
// The key. 
$key = ''; 
  
// The args. 
$args = null; 
  
// (default: null) 
$value = null; 
  
// NOTICE! Understand what this does before running. 
$result = woocommerce_form_field($key, $args, $value); 
    

Defined – محل تعریف

/includes/wc-template-functions.php

function woocommerce_form_field( $key, $args, $value = null ) { 
    $defaults = array( 
        'type' => 'text',  
        'label' => '',  
        'description' => '',  
        'placeholder' => '',  
        'maxlength' => false,  
        'required' => false,  
        'autocomplete' => false,  
        'id' => $key,  
        'class' => array(),  
        'label_class' => array(),  
        'input_class' => array(),  
        'return' => false,  
        'options' => array(),  
        'custom_attributes' => array(),  
        'validate' => array(),  
        'default' => '',  
        'autofocus' => '',  
        'priority' => '',  
 ); 
 
    $args = wp_parse_args( $args, $defaults ); 
    $args = apply_filters( 'woocommerce_form_field_args', $args, $key, $value ); 
 
    if ( $args['required'] ) { 
        $args['class'][] = 'validate-required'; 
        $required = ' *'; 
    } else { 
        $required = ''; 
    } 
 
    if ( is_string( $args['label_class'] ) ) { 
        $args['label_class'] = array( $args['label_class'] ); 
    } 
 
    if ( is_null( $value ) ) { 
        $value = $args['default']; 
    } 
 
    // Custom attribute handling 
    $custom_attributes = array(); 
    $args['custom_attributes'] = array_filter( (array) $args['custom_attributes'] ); 
 
    if ( $args['maxlength'] ) { 
        $args['custom_attributes']['maxlength'] = absint( $args['maxlength'] ); 
    } 
 
    if ( ! empty( $args['autocomplete'] ) ) { 
        $args['custom_attributes']['autocomplete'] = $args['autocomplete']; 
    } 
 
    if ( true === $args['autofocus'] ) { 
        $args['custom_attributes']['autofocus'] = 'autofocus'; 
    } 
 
    if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) { 
        foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) { 
            $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; 
        } 
    } 
 
    if ( ! empty( $args['validate'] ) ) { 
        foreach ( $args['validate'] as $validate ) { 
            $args['class'][] = 'validate-' . $validate; 
        } 
    } 
 
    $field = ''; 
    $label_id = $args['id']; 
    $sort = $args['priority'] ? $args['priority'] : ''; 
    $field_container = '

%3$s

'; switch ( $args['type'] ) { case 'country' : $countries = 'shipping_country' === $key ? WC()->countries->get_shipping_countries() : WC()->countries->get_allowed_countries(); if ( 1 === sizeof( $countries ) ) { $field .= '' . current( array_values( $countries ) ) . ''; $field .= ''; } else { $field = ''; $field .= ''; } break; case 'state' : /** Get Country */ $country_key = 'billing_state' === $key ? 'billing_country' : 'shipping_country'; $current_cc = WC()->checkout->get_value( $country_key ); $states = WC()->countries->get_states( $current_cc ); if ( is_array( $states ) && empty( $states ) ) { $field_container = ''; $field .= ''; } elseif ( ! is_null( $current_cc ) && is_array( $states ) ) { $field .= ''; } else { $field .= ''; } break; case 'textarea' : $field .= ''; break; case 'checkbox' : $field = ''; break; case 'password' : case 'text' : case 'email' : case 'tel' : case 'number' : $field .= ''; break; case 'select' : $options = $field = ''; if ( ! empty( $args['options'] ) ) { foreach ( $args['options'] as $option_key => $option_text ) { if ( '' === $option_key ) { // If we have a blank option, select2 needs a placeholder if ( empty( $args['placeholder'] ) ) { $args['placeholder'] = $option_text ? $option_text : __( 'Choose an option', woocommerce ); } $custom_attributes[] = 'data-allow_clear="true"'; } $options .= ''; } $field .= ''; } break; case 'radio' : $label_id = current( array_keys( $args['options'] ) ); if ( ! empty( $args['options'] ) ) { foreach ( $args['options'] as $option_key => $option_text ) { $field .= ''; $field .= ''; } } break; } if ( ! empty( $field ) ) { $field_html = ''; if ( $args['label'] && 'checkbox' != $args['type'] ) { $field_html .= ''; } $field_html .= $field; if ( $args['description'] ) { $field_html .= '' . esc_html( $args['description'] ) . ''; } $container_class = esc_attr( implode( ' ', $args['class'] ) ); $container_id = esc_attr( $args['id'] ) . '_field'; $field = sprintf( $field_container, $container_class, $container_id, $field_html ); } $field = apply_filters( 'woocommerce_form_field_' . $args['type'], $field, $key, $args, $value ); if ( $args['return'] ) { return $field; } else { echo $field; } }

versions – نسخه ها

از نسخه : 3.0.2

نسخه فعلی : 3.0.6

دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2

ارسال نظر

جهت استفاده از کد حتما از تگ pre استفاده نمایید .

contact us