/* nuovo test custom field*/
add_action( 'woocommerce_before_order_notes', 'persons_details' );
function persons_details( $checkout ) {
$count = WC()->cart->get_cart_contents_count();
$i = 0;
for( $k=1; $k<= $count; $k++ ) {
$i++;
echo '<div><strong>'. __('Dati iscritto n. ') . $i . '</strong></div>';
woocommerce_form_field( 'cstm_full_name' . $i, array(
'type' => 'text',
'class' => array('my-field-class form-row-first'),
'label' => __("Nome e cognome"),
'placeholder' => __(""),
'required' => true,
), $checkout->get_value( 'cstm_full_name' . $i ));
woocommerce_form_field( 'cstm_email' . $i, array(
'type' => 'email',
'class' => array( 'my-field-class form-row-last' ),
'label' => __( "Email" ),
'placeholder' => __(""),
'required' => true,
), $checkout->get_value( 'cstm_email' . $i ));
woocommerce_form_field( 'cstm_phone' . $i, array(
'type' => 'text',
'class' => array('my-field-class form-row-first'),
'label' => __("Numero di telefono"),
'placeholder' => __(""),
'required' => true,
), $checkout->get_value( 'cstm_phone' . $i ));
woocommerce_form_field( 'cstm_address' . $i, array(
'type' => 'textarea',
'class' => array('my-field-class form-row-last'),
'label' => __("Indirizzo di residenza"),
'placeholder' => __(""),
'required' => true,
), $checkout->get_value( 'cstm_address' . $i ));
echo '<div class="clear"></div>
<div class="clearbox"></div>';
}
}
add_action( 'woocommerce_checkout_create_order', 'save_custom_checkout_field_order_meta' );
function save_custom_checkout_field_order_meta( $order )
{
$count = WC()->cart->get_cart_contents_count();
$order->update_meta_data( 'cstm_items_count', intval($count) ); // Save the cart contents count as meta data
$i = 0;
for($k=1; $k<= $count; $k++) {
$i++;
if ( isset($_POST['cstm_full_name'.$i]) && ! empty($_POST['cstm_full_name'.$i]) ) {
$order->update_meta_data( 'cstm_full_name'.$i, sanitize_text_field($_POST['cstm_full_name'.$i]) );
}
if ( isset($_POST['cstm_email'.$i]) && ! empty($_POST['cstm_email'.$i]) ) {
$order->update_meta_data( 'cstm_email'.$i, sanitize_text_field($_POST['cstm_email'.$i]) );
}
if ( isset($_POST['cstm_phone'.$i]) && ! empty($_POST['cstm_phone'.$i])) {
$order->update_meta_data( 'cstm_phone'.$i, sanitize_text_field($_POST['cstm_phone'.$i]) );
}
if ( isset($_POST['cstm_address'.$i]) && ! empty($_POST['cstm_address'.$i])) {
$order->update_meta_data( 'cstm_address'.$i, sanitize_text_field($_POST['cstm_address'.$i]) );
}
}
}
add_action( 'woocommerce_email_order_meta', 'add_email_custom_order_meta', 10, 3 );
function add_email_custom_order_meta( $order, $sent_to_admin, $plain_text ){
$quantity = $order->get_meta('cstm_items_count'); // Get items quantity count from meta data
echo '<ul>';
$i = 0;
for( $k=1; $k <= $quantity; $k++ ) {
$i++;
echo '<li><strong>'. __("Dati iscritto n. ") . $i . '<strong></li>
<li>' . __("Nome e cognome: ") . $order->get_meta('cstm_full_name'.$i) . '</li>
<li>' . __("Email: ") . $order->get_meta('cstm_email'.$i) . '</li>
<li>' . __("Numero di telefono: ") . $order->get_meta('cstm_phone'.$i) . '</li>
<li>' . __("Indirizzo di residenza: ") . $order->get_meta('cstm_address'.$i) . '</li>';
}
echo '</ul>';
}
add_action( 'woocommerce_admin_order_data_after_order_details', 'display_custom_fields_in_admin_order_pages' );
function display_custom_fields_in_admin_order_pages( $order ){
$quantity = $order->get_meta('cstm_items_count'); // Get items quantity count from meta data
echo '<div class="order_data_column" style="width: 100% !important;">
<h4>' . __( 'Your label' ) . '</h4>
<ul>';
$i = 0;
for( $k=1; $k <= $quantity; $k++ ) {
$i++;
echo '<li><strong>'. __("Dati iscritto n. ") . $i . '<strong></li>
<li>' . __("Nome e cognome: ") . $order->get_meta('cstm_full_name'.$i) . '</li>
<li>' . __("Email: ") . $order->get_meta('cstm_email'.$i) . '</li>
<li>' . __("Numero di telefono: ") . $order->get_meta('cstm_phone'.$i) . '</li>
<li>' . __("Indirizzo di residenza: ") .$order->get_meta('cstm_address'.$i) . '</li>';
}
echo '</ul>
</div>';
}
phpwordpresswoocommerceguardareCampi personalizzati
Condividere
Modificare
Eliminare
Bandiera
modificato il 16 giugno alle 8:41
ha chiesto l'8 giugno alle 5:51
L'avatar dell'utente di LesCa
Les Ca
2144 distintivi in ??bronzo
@LoicTheAztec hai chiuso la domanda ma ho provato anche le vecchie domande ma non riesco a capire dove sbaglio, continuo a non vedere il valore dei campi nelle email e nella pagina di amministrazione dell'ordine. Vorrei che tu potessi anche modificare i campi dalla pagina di amministrazione dell'ordine in caso di errori
–
Les Ca
8 giugno alle 14:39 Eliminare
]]>I have created few custom fields on lead entity in D365 CE. However, when I try to access those fields in WordPress those are read-only mode. Can anyone please help me on this issue.
]]>After i implemented this my site started doing weird thing, its not loading the media page in my backend after i saved this code and i cannot publish my page anymore as it gives the error “Looks like something’s gone wrong. Wait a couple seconds, and then try again.” on this link are screenshots of the errors.
I made some changes in the code of the documentation the following code is in my functions.php file:
<!-- add a extra field for phone number to sign up form -->
<?php function woocom_extra_register_fields() {?>
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone'] ); ?>" /></p>
<?php
}
add_action( 'woocommerce_register_form_start', 'woocom_extra_register_fields' );
// add validation to the field above
function woocom_validate_extra_register_fields( $username, $email, $validation_errors )
{
if (isset($_POST['billing_phone']) && empty($_POST['billing_phone']) ) {
$validation_errors->add('billing_phone_error', __('Telefoon is verplicht', 'woocommerce'));
}
return $validation_errors;
}
add_action('woocommerce_register_post', 'woocom_validate_extra_register_fields', 10, 3);
// add the added data to the database
function woocom_save_extra_register_fields($customer_id) {
if (isset($_POST['billing_phone'])) {
update_user_meta($customer_id, 'billing_phone', sanitize_text_field($_POST['billing_phone']));
}
}
add_action('woocommerce_created_customer', 'woocom_save_extra_register_fields');
Does someone know how to fix my problem?
Kind regards,
René
I’m using catlist with a template.
In this template I’m reading my custom fields: $lcp_display_output .= $this->get_custom_fields($post);
On a page I display the customfields using [catlist customfield_display_name="yes"]
.
Instead of the NAME, I would like to use the LABEL.
That label is used on the edit screen.
How do I display that label on my page?
F.i.: [catlist customfield_display_label="yes"]
this doesn’t do the trick
I’m trying to create an archive page with a dropdown filter that allows the user to filter contents that contain the value “aperta” or “chiusa”.
This is what I did till now (the query doesn’t filter correctly).
<form method="post" action="<?php the_permalink() ?>">
<select name="my_status" id="stato" class="postform" onchange="submit();">
<option selected="selected">Choose a status</option>
<option value="aperta">Aperta</option>
<option value="chiusa">Chiusa</option>
</select>
</form>
<?php /* Reset filter */ ?>
<p><a href="<?php the_permalink(); ?>">Clear filter</a></p>
<?php
if( !isset($_POST['my_status']) || '' == $_POST['my_status']) {
}
else {
$stato = $_POST['my_status'];
// Create new query
$query = new WP_Query( array(
'post_type'=> 'offerta_lavoro', // your CPT
'post_status' => 'publish',
'meta_query'=>array(
array(
'key' => 'crb_attiva_nonattiva',
'value' => $stato,
),
),
) );
// Loop
if($query->have_posts()):
while( $query->have_posts() ): $query->the_post();
endwhile;
endif;
// reset query to default
wp_reset_postdata();
} ?>
Where is my mistake?
Thanks in advance, I hope my explanation is clear enough.
]]>WHAT I DID:
from wp-admin
Custom Fields > Add New > Add title > + Add Field
provided:
Field Label
Field Type: Relational > Relationship
Filter by Post Type: selected custom-post-type-A
Filters: unchecked Post Type & Taxonomy
Location Rules: Post Type is equal to custom-post-type-B
Publish
Now, when I go to edit an entry from custom-post-type-B, the Custom Field is present, but none of my available custom-post-type-A entries are available for selection, either by default or by ‘Search…’
I am not finding a solution on my own, asking for assistance in understanding
]]>I reached out to the support team & in less than 24hrs they got me support & also got my problem fixed.
I couldn’t rate these guys higher than 5 but if i could i would.
Thanks & keep up the great work.
]]>I build a site with an advanced real estate search via ajax. The search works fine. But when there are more than seven meta_queries, the query really slows down extremly.
I did some speed tests. Using 7 meta queries: 3 seconds, 8 meta queries: 22 seconds, 9 meta queries: 36 seconds.
This is the code I am using for adding the real estate options to the query.
if (null !== ($_POST['du']) && $_POST['du'] != 0) {
$args['meta_query'][] = array(
'key' => 'badezimmer',
'value' => sanitize_text_field($_POST['du']),
'type' => 'numeric',
'compare' => '>='
);
}
Is there something I can do to optimize the speed?
Thanks!
]]>Even purchased the “custom fields” addon which included the very decent support function.
Recommended!
]]>