wordpress acf form display data orderby order_no - wordpress

For ACF form plugin, I used field group function which contains 10 fields, and loop to display in post like below:
<?php $fields = get_field_objects($post_id);
if( $fields)
{
foreach( $fields as $field_name => $field )
{
if($field['type']=='text' || $field['type']=='textarea' ){
echo '<li>';
echo '<label>' . $field['label'] . '</label>';
echo '<span>' . $field['value'] . '</span>';
echo '<span>' . $field['order_no'] . '</span>';
echo '</li>';
}
}
}?>
Now I want to sort it by order_no, how can I do it?

You could try something like that before you print out:
function objectSort( $a, $b ) {
return $a->order_no == $b->order_no ? 0 : ( $a->order_no > $b->order_no ) ? 1 : -1;
}
usort( $fields, 'objectSort' );
Note: This is not meant to be a full correct code, I just want to give you an idea for the solution.

Related

How can I edit the ratings output in woocommerce to remove the text and just how the stars without using css

I'm new to coding and wordpress/woocommerce and am trying to find a simple way to edit the output of wc_get_rating_html.
At the moment it outputs the following:
function wc_get_rating_html( $rating ) {
if ( $rating > 0 ) {
$rating_html = '<div class="star-rating" title="' . sprintf( esc_attr__( 'Rated %s out of 5', 'woocommerce' ), $rating ) . '">';
$rating_html .= '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%"><strong class="rating">' . $rating . '</strong> ' . esc_html__( 'out of 5', 'woocommerce' ) . '</span>';
$rating_html .= '</div>';
} else {
$rating_html = '';
}
return apply_filters( 'woocommerce_product_get_rating_html', $rating_html, $rating );
}
I simply want to output the star rating and not the text that goes before and after. Any suggestions on how i can do this as i obv cant edit the template file. thanks
Wordpress utilizes filters which allow you to replace and/or modify the output of what the filter processes. Here is the full block for the wc_get_rating_html function:
function wc_get_rating_html( $rating, $count = 0 ) {
$html = '';
if ( 0 < $rating ) {
/* translators: %s: rating */
$label = sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $rating );
$html = '<div class="star-rating" role="img" aria-label="' . esc_attr( $label ) . '">' . wc_get_star_rating_html( $rating, $count ) . '</div>';
}
return apply_filters( 'woocommerce_product_get_rating_html', $html, $rating, $count );
}
In your example, woocommerce_product_get_rating_html is the filter name and takes three arguments:
$rating_html which represents the output which the user sees
$rating which is the numerical rating
$count which is the total number of ratings.
If you wish to replace the output, you'll need to hook into the filter woocommerce_product_get_rating_html with a function that will return the modified content. You'll definitely need to review Hooks & Filters and how they work in Wordpress if you are not familiar with utilizing hooks and filters in Wordpress.

Custom Option Cart Woocommerce

to everyone !
Someone can help me with my proyect, Is very simple but I have one thing that makes me crazy.
I have this:
every checkbox have a value (additional value price)
I need change the price wen I checked in one, two or all checkbox and save this options to send it to the checkout and email....And show this options to order information in the back-end.
add_filter( 'woocommerce_cart_item_name', 'custom_cart_item_name', 10, 3 );
function custom_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
if( ! is_cart() )
return $item_name;
$item_name .= $value3.'<div class="lineList">';
$value2 = $cart_item['data']->get_meta('_preciosCata');
if( $value1 = $cart_item['data']->get_meta('_varArrayTitle') ) {
for ($i=0;$i<count($value1); $i++) {
//$item_name .= '<div class="lineOne lorem"><input type="checkbox" name="cart[%s][lorem]" id="addPrice" value="' . $value2[$i] . '"> <span class="custom-field"> ' . $value1[$i] . ' </span></div>';
$item_name .= sprintf( '<div class="lineOne lorem"><input type="checkbox" id="_checkbox' . $i . '" name="_checkbox' . $i . '" value="' . $value2[$i] . '" class="checkedBox url text" /> <span class="custom-field">' . $value3.$value1[$i] . ' </span></div>', $cart_item_key, esc_attr( $values['url'] ) );
}
}
$item_name .= '</div>';
return $item_name;
}
I update the car here but dont save the value:
add_action( 'wp_footer', 'bbloomer_cart_refresh_update_qty' );
function bbloomer_cart_refresh_update_qty() {
if (is_cart()) {
?>
<script>
jQuery('div.woocommerce').on('change', '.checkedBox', function(){
jQuery("[name='update_cart']").prop("disabled", false);
jQuery("[name='update_cart']").trigger("click");
//alert($(this).val());
});
</script>
<?php
}
}
I need help please

Hide certain acf fields wordpress

Help
Code in template:
<?php
$groupID = '';
$fields = get_fields($groupID);
$fields = get_field_objects();
if( $fields )
{
foreach( $fields as $field_name => $field )
{
if( $field['value'] )
{
echo '<ul>';
echo '<li>' . $field['label'] . ': <strong>' . $field['value'] . '</strong></li>';
echo '</ul>';
}
}
}
?>
I need to hide the fields:
  field_5c0a8d44cf56e
  field_5c0a8d4ecf56f
How can i do this?
Your question is not much clear for me, and from my knowledge what I have understood,
for an acf group you don't want to loop through, the control is yours,
so you can print it straightaway
but if you really want to do it in a loop then,
if( $fields )
{
foreach( $fields as $field_name => $value )
{
if( $value && !in_array($field_name, ["field_5c0a8d44cf56e", "field_5c0a8d4ecf56f"])
{
echo '<ul>';
echo '<li>' . $field_name . ': <strong>' . $value . '</strong></li>';
echo '</ul>';
}
}
}

Display Post Terms and add link

I've created this shortcode to display my terms (custom taxonomy) on specific post (custom post types) :
// First we create a function
function list_terms_forme_juridique_taxonomy() {
global $post;
$terms = wp_get_post_terms( $post->ID, 'forme_juridique',array('fields'
=> 'names') );
ob_start();
if( count( $terms) > 0) {
echo '<ul>';
echo '<li>' . implode( '</li><li>', $terms) . '</li>';
echo '</ul>';
}
return ob_get_clean();
}
// Add a shortcode that executes our function
add_shortcode( 'forme_juridique', 'list_terms_forme_juridique_taxonomy'
);
I am trying to add a link (url) on my terms in order to redirect to the term page but I didn't succeed yet.
Any help ?
Use get_term_link()function for this:
// First we create a function
function list_terms_forme_juridique_taxonomy() {
global $post;
$terms = wp_get_post_terms($post->ID, 'forme_juridique');
ob_start();
if( count( $terms) > 0) {
echo '<ul>';
foreach($terms as $term){
$term_link = get_term_link($term, 'forme_juridique');
echo '<li>' . $term->name . '</li>';
}
echo '</ul>';
}
return ob_get_clean();
}
// Add a shortcode that executes our function
add_shortcode( 'forme_juridique', 'list_terms_forme_juridique_taxonomy'
);

Insert custom content in WooCommerce

I have some problem in WooCommerce Admin Order menu. I want to add some content in the column but I don't know where I can make it.
This is some example screenshoot about my woocommerce admin order view :
I want to add phone number bellow email address in Order column.
Please help me to do that.
Thank you.
I've had to do this once, i've followed this tutorial :
https://code.tutsplus.com/articles/add-a-custom-column-in-posts-and-custom-post-types-admin-screen--wp-24934
add_action('manage_shop_order_posts_custom_column', 'match_order_woocommerce_custom_order_columns', 2);
function match_order_woocommerce_custom_order_columns( $column ) {
remove_action('manage_shop_order_posts_custom_column', 'woocommerce_custom_order_columns', 2);
global $post, $woocommerce;
$order = new WC_Order( $post->ID );
switch ($column) {
case "order_title" :
if ($order->user_id) $user_info = get_userdata($order->user_id);
if (isset($user_info) && $user_info) :
$user = '<a href="user-edit.php?user_id=' . esc_attr( $user_info->ID ) . '">';
if ($user_info->first_name || $user_info->last_name) $user .= $user_info->first_name.' '.$user_info->last_name;
else $user .= esc_html( $user_info->display_name );
$user .= '</a>';
else :
$user = __('Guest', 'woocommerce');
endif;
echo '<strong>'.sprintf( __('Order %s', 'woocommerce'), $order->get_order_number() ).'</strong> ' . __('made by', 'woocommerce') . ' ' . $user;
if ($order->billing_email) :
echo '<small class="meta">'.__('Email:', 'woocommerce') . ' ' . ''.esc_html( $order->billing_email ).'</small>';
endif;
if ($order->billing_phone) :
echo '<small class="meta">'.__('Tel:', 'woocommerce') . ' ' . esc_html( $order->billing_phone ) . '</small>';
endif;
break;
}
}
Please try this snippet in your active theme's functions.php

Resources