Firstly, I explain what do I want. I want to get product reviews from the product-bought customer on the order-details page. I copied the code from my current theme > woocommerce > single-product-reviews.php. After I pasted the code on order-details-item.php page.
I can pass the this if:
<?php if ( get_option( ‘woocommerce_review_rating_verification_required’ ) === ‘no’ || wc_customer_bought_product( ”, get_current_user_id(), $sub_product->get_id() ) ) : ?>
I coded similar the single-product-reviews.php but
comment_form( apply_filters( ‘woocommerce_product_review_comment_form_args’, $comment_form ) ); function is not working so the form didn’t come on the order-details-item.php
Whan can I do ?`
<?php
/**
* Order Item Details
*
* This template can be overridden by copying it to yourtheme/woocommerce/order/order-details-item.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #package WooCommerce/Templates
* #version 3.7.0
*/
if (!defined('ABSPATH')) {
exit;
}
global $wp;
global $wpdb;
$current_url = home_url(add_query_arg(array(), $wp->request));
$order_items = $order->get_items(apply_filters('woocommerce_purchase_order_item_types', 'line_item'));
$main_order_id = wp_get_post_parent_id($order->get_id());
// set the meta_key to the appropriate custom field meta_key1 and meta_key2
$meta_key1 = $order->get_id();
$allmiles = $wpdb->get_var(
$wpdb->prepare(
"
SELECT item_qtys
FROM $wpdb->dokan_refund
WHERE order_id =%d
",
$meta_key1
)
);
if (empty($sub_orders)) {
if ($main_order_id!=0){
echo sprintf('
<a id="button-go"
href="' ."%s/hesabim/siparisi-goruntule/%d/". '"
style="border-radius: 4px;border:1px solid #92cecc; background-color: white;color:#92cecc;margin-top:5px;margin-bottom:5px;"
data-id="35375"
class="woocommerce-Button button woocommerce-column__title">%s</a>',
home_url(),wp_kses_post($main_order_id), 'Ana Siparişe Geri Dön');
}
foreach ($order_items as $item_id => $item) {
if (!apply_filters('woocommerce_order_item_visible', true, $item)) {
return;
}
$product_delivery_date = get_post_meta($item->get_product_id(), '_kargo_verilis_suresi', true);
$product_id=$item->get_product_id();
$sub_product=wc_get_product( $product_id );
$product_meta = get_post_meta($item->get_product_id());
$sub_refund_start = wc_get_order_item_meta($item_id, 'sub_status', true);
// $sub_item_status=wc_add_order_item_meta( $item_id, 'item_status_custom', $order->get_status(), $unique = false )
$tarih = explode('T', $order->get_date_completed());
$now = date("Y-m-d");
$origin = date_create($tarih[0]);
$target = date_create($now);
$interval = date_diff($origin, $target);
$iade_hakki = $interval->d;
$aide_yazi = '';
$refund = $item_id;
if (strpos($allmiles, strval($item_id)) > 0) {
$sub_item_status = $wpdb->get_var(
$wpdb->prepare(
"
SELECT status
FROM $wpdb->dokan_refund
WHERE order_id =%d
",
$meta_key1
)
);
switch ($sub_item_status) {
case "0":
$sub_item_status = 'Alıcı Iadesi Bekleniyor';
break;
case "1":
$sub_item_status = 'İade Onaylandı';
break;
case "2" :
$sub_item_status = 'İade Onaylanmadı';
break;
}
} else {
if (!empty($sub_refund_start)) {
$sub_item_status = $sub_refund_start;
} else {
$sub_item_status = $order->get_status();
}
}
?>
<?php
?>
<tr class="<?php echo esc_attr(apply_filters('woocommerce_order_item_class', 'woocommerce-table__line-item order_item', $item, $order)); ?>">
<div class="customer-order-detail-custom">
<div class="customer-order-detail-top-custom ">
<div class="left">
<div class="seller-custom-name">
<?php
$dizge = do_action('woocommerce_order_item_meta_start', $item_id, $item, $order, false);
// echo esc_html( $dizge);
?>
</div>
<div class="custom-sub-id">
Alt Sipariş No:
<span>
<?= wp_kses_post($order->get_id()) ?>
</span>
</div>
<div class="custom-sub-order-status">
Sipariş Durumu:
<span class="sub-order-status__<?= esc_attr__($order->get_status()) ?>">
<?= wp_kses_post(wc_get_order_status_name($order->get_status())) ?>
</span>
</div>
</div>
<div class="right">
<div class="custom-sub-order-total">
Tutar:
<span>
<?php
echo $order->get_formatted_line_subtotal($item);
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</span>
</div>
</div>
</div>
<div class="customer-order-detail-bottom-custom">
<!-- order image start-->
<div class="bottom-image-custom">
<?= wp_kses_post(wp_get_attachment_image($product_meta['_thumbnail_id'][0], 'full')) ?>
</div>
<!-- order image end-->
<!-- order desc start-->
<div class="bottom-desc-custom">
<div class="desc">
<?php
$is_visible = $product && $product->is_visible();
$product_permalink = apply_filters('woocommerce_order_item_permalink', $is_visible ? $product->get_permalink($item) : '', $item, $order);
echo apply_filters('woocommerce_order_item_name', $product_permalink ? sprintf('%s', $product_permalink, $item->get_name()) : $item->get_name(), $item, $is_visible); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</div>
<div class="sub-meta">
<div class="size">
Beden:
<span>Tek Ebat</span>
</div>
<div class="qty">
<?php
$qty = $item->get_quantity();
$refunded_qty = $order->get_qty_refunded_for_item($item_id);
if ($refunded_qty) {
$qty_display = '<del>' . esc_html($qty) . '</del> <ins>' . esc_html($qty - ($refunded_qty * -1)) . '</ins>';
} else {
$qty_display = esc_html($qty);
}
echo apply_filters('woocommerce_order_item_quantity_html', ' Adet: <strong class="product-quantity">' . sprintf('%s', $qty_display) . '</strong>', $item); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</div>
</div>
<?php
// wc_display_item_meta($item); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
do_action('woocommerce_order_item_meta_end', $item_id, $item, $order, false);
?>
</div>
<!--order desc end-->
<!--order button start-->
<!-- <div class="bottom-button-custom">-->
<!-- --><?php
// global $wp;
// $current_url = home_url(add_query_arg(array(), $wp->request));
// if ($sub_item_status=="completed") {
// if ($iade_hakki>=14){
// echo sprintf('
// <button id="button-sub-iade"
// style="border-radius: 4px;border:2px solid #92cecc; background-color: white;color:#92cecc"
// data-id="'.esc_attr__("%d").'"
// class="woocommerce-Button button woocommerce-column__title">
// %s </button>',
// wp_kses_post($order->get_id()), esc_html('İade Et'));
//
//
// } else{ }
// }
// elseif ($sub_item_status=="shipped" ){
// echo sprintf('
// <button id="button-sub-iade"
// style="border-radius: 4px;border:2px solid #FF9D78; background-color: white;color:#FF9D78"
// data-id="'.esc_attr__("%d").'"
// data-name="'.esc_attr__("%s").'"
// data-item="'.esc_attr__("%d").'"
// data-redirect="'.esc_url("%s").'"
// class="woocommerce-Button button woocommerce-column__title sub-iade">
// %s </button>',
// wp_kses_post($order->get_id()),wp_kses_post($item->get_name()),wp_kses_post($item_id) ,wp_kses_post($current_url),esc_html('İade Et'));
// }
//
// elseif ($sub_item_status=='on-hold' | $sub_item_status=='processing' ){
// echo sprintf('
// <button id="button-sub-iptal"
// style="border-radius: 4px;border:1px solid #92cecc; background-color: white;color:#92cecc"
// data-id="'.esc_attr__("%d").'"
// data-name="'.esc_attr__("%s").'"
// data-item="'.esc_attr__("%d").'"
// data-redirect="'.esc_url("%s").'"
// class="woocommerce-Button button woocommerce-column__title sub-iptal">
// %s </button>',
// wp_kses_post($order->get_id()),wp_kses_post($item->get_name()),wp_kses_post($item_id) ,wp_kses_post($current_url),esc_html('İptal Et'));
// }else{ echo '';}?>
<!---->
<!---->
<!---->
<!-- </div>-->
<!--order button end-->
</div>
<div class="customer-order-detail-bottom-custom mobile">
<div class="sub-order-total-text-mobile">
Tutar:
</div>
<div class="sub-order-total-digit-mobile">
<?php echo $order->get_formatted_line_subtotal($item); ?>
</div>
</div>
<?php if ($order->get_status() == 'refunded-customer' || $order->get_status() == 'shipped-refunded'): ?>
<div class="customer-refund-main">
<div class="refund-text">
<div class="custom-refund-text">
<?= esc_html_e('İade Talebi Oluşturuldu', 'yk-plugin') ?>
<p><?= esc_html_e('İade onaylandığında iade tutarı hesabınıza aktarılacaktır.', 'yk-plugin') ?></p>
</div>
<br>
<div class="refund-shipping-desc">
<?= _e('İade edeceğiniz ürünü <b>faturası ile birlikte</b> tek bir pakete koyunuz..', 'yk-plugin') ?>
<p><?= _e('Paketi iade kodunuzla birlikte <b>en geç 7 iş günü</b> içinde MNG Kargo’ya verin', 'yk-plugin') ?></p>
</div>
</div>
<div class="refund-shipped">
<div class="shipping-brand">
<div class="shipping-brand-text">
Kargo Firması
</div>
<div class="shipping-brand-img">
<img src="<?= esc_url('https://hstaging.yuvanikur.com/wp-content/plugins/yk-plugin-v1.3/inc/assets/svg/357048.svg') ?>"
alt="">
</div>
</div>
<div class="shipping-brand">
<div class="shipping-brand-text">
Kargo Iade Kodu
</div>
<div class="shipping-brand-code">
1234567891234
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
<div id="reviews" class="woocommerce-Reviews">
<div id="comments">
<h2 class="woocommerce-Reviews-title">
<?php
$count = $sub_product->get_review_count();
if ( $count && wc_review_ratings_enabled() ) {
/* translators: 1: reviews count 2: product name */
$reviews_title = sprintf( esc_html( _n( '%1$s review for %2$s', '%1$s reviews for %2$s', $count, 'woocommerce' ) ), esc_html( $count ), '<span>' . $sub_product->get_title(). '</span>' );
echo apply_filters( 'woocommerce_reviews_title', $reviews_title, $count, $sub_product ); // WPCS: XSS ok.
} else {
esc_html_e( 'Reviews', 'woocommerce' );
}
?>
</h2>
<?php if ( have_comments() ) : ?>
<ol class="commentlist">
<?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments' ) ) ); ?>
</ol>
<?php
if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
echo '<nav class="woocommerce-pagination">';
paginate_comments_links(
apply_filters(
'woocommerce_comment_pagination_args',
array(
'prev_text' => is_rtl() ? '→' : '←',
'next_text' => is_rtl() ? '←' : '→',
'type' => 'list',
)
)
);
echo '</nav>';
endif;
?>
<?php else : ?>
<p class="woocommerce-noreviews"><?php esc_html_e( 'There are no reviews yet.', 'woocommerce' ); ?></p>
<?php endif; ?>
</div>
<?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $sub_product->get_id() ) ) : ?>
<div id="review_form_wrapper">
<div id="review_form">
<?php
$commenter = wp_get_current_commenter();
$comment_form = array(
/* translators: %s is product title */
'title_reply' => have_comments() ? esc_html__( 'Add a review', 'woocommerce' ) : sprintf( esc_html__( 'Be the first to review “%s”', 'woocommerce' ), $sub_product->get_title() ),
/* translators: %s is product title */
'title_reply_to' => esc_html__( 'Leave a Reply to %s', 'woocommerce' ),
'title_reply_before' => '<span id="reply-title" class="comment-reply-title">',
'title_reply_after' => '</span>',
'comment_notes_after' => '',
'label_submit' => esc_html__( 'Submit', 'woocommerce' ),
'logged_in_as' => '',
'comment_field' => '',
);
$name_email_required = (bool) get_option( 'require_name_email', 1 );
$fields = array(
'author' => array(
'label' => __( 'Name', 'woocommerce' ),
'type' => 'text',
'value' => $commenter['comment_author'],
'required' => $name_email_required,
),
'email' => array(
'label' => __( 'Email', 'woocommerce' ),
'type' => 'email',
'value' => $commenter['comment_author_email'],
'required' => $name_email_required,
),
);
$comment_form['fields'] = array();
foreach ( $fields as $key => $field ) {
$field_html = '<p class="comment-form-' . esc_attr( $key ) . '">';
$field_html .= '<label for="' . esc_attr( $key ) . '">' . esc_html( $field['label'] );
if ( $field['required'] ) {
$field_html .= ' <span class="required">*</span>';
}
$field_html .= '</label><input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" type="' . esc_attr( $field['type'] ) . '" value="' . esc_attr( $field['value'] ) . '" size="30" ' . ( $field['required'] ? 'required' : '' ) . ' /></p>';
$comment_form['fields'][ $key ] = $field_html;
}
if ( wc_review_ratings_enabled() ) {
$comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'woocommerce' ) . ( wc_review_ratings_required() ? ' <span class="required">*</span>' : '' ) . '</label><select name="rating" id="rating" required>
<option value="">' . esc_html__( 'Rate…', 'woocommerce' ) . '</option>
<option value="5">' . esc_html__( 'Perfect', 'woocommerce' ) . '</option>
<option value="4">' . esc_html__( 'Good', 'woocommerce' ) . '</option>
<option value="3">' . esc_html__( 'Average', 'woocommerce' ) . '</option>
<option value="2">' . esc_html__( 'Not that bad', 'woocommerce' ) . '</option>
<option value="1">' . esc_html__( 'Very poor', 'woocommerce' ) . '</option>
</select></div>';
}
$comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . esc_html__( 'Your review', 'woocommerce' ) . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" required></textarea></p>';
comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );
?>
</div>
</div>
<?php else : ?>
<p class="woocommerce-verification-required"><?php esc_html_e( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ); ?></p>
<?php endif; ?>
<div class="clear"></div>
</div>
</tr>
<?php if ($show_purchase_note && $purchase_note) : ?>
<tr class="woocommerce-table__product-purchase-note product-purchase-note">
<td colspan="2"><?php echo wpautop(do_shortcode(wp_kses_post($purchase_note))); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
</tr>
<?php endif; ?>
<?php }
} ?>
I found my solution. I found my solution. Woocommerce does not allow review for the product on the account page. My solution is simple.
comment_form( apply_filters( ‘woocommerce_product_review_comment_form_args’, $comment_form ),$product_id );
I gave the product id to the function because woocommerce allow review on a single product page. It's a simple trick.
Have this code in: woocommerce/templates/myaccount/view-order.php
defined( 'ABSPATH' ) || exit;
$notes = $order->get_customer_order_notes();
?>
<p>
<?php if ( $notes ) : ?>
<h2><?php esc_html_e( 'Order updates', 'woocommerce' ); ?></h2>
<ol class="woocommerce-OrderUpdates commentlist notes">
<?php foreach ( $notes as $note ) : ?>
<li class="woocommerce-OrderUpdate comment note">
<div class="woocommerce-OrderUpdate-inner comment_container">
<div class="woocommerce-OrderUpdate-text comment-text">
<p class="woocommerce-OrderUpdate-meta meta"><?php echo date_i18n( esc_html__( 'l jS \o\f F Y, h:ia', 'woocommerce' ), strtotime( $note->comment_date ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
<div class="woocommerce-OrderUpdate-description description">
<?php echo wpautop( wptexturize( $note->comment_content ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
It shows the notes I can send to customer in WC orders. That info is under My account -> orders -> view order for the customer but I'd like to display that note in customer dashboard instead of view order.
I tried copying it to the dashboard.php but it just threw an error and said that get_customer_order_notes() is null.
I'm a beginner in php and it's my first WC site so any help would be much appreciated.
How can I add my ACF field into another plugin's form?
I tried this but this does not work
<div class="input-group">
<label for="deal_title"><?php _e('Deal title', 'wcd'); ?> <span class="required">*</span></label>
<input type="text" name="deal_title" id="deal_title" value="<?php echo esc_attr($deal_title) ?>" class="form-control" data-validation="required" data-error="<?php esc_attr_e('Please input deal description', 'wcd'); ?>">
<p class="description"><?php _e('Input title for the deal.', 'wcd'); ?></p>
</div>
//This is the part I want my ACF field
<?php echo the_field('business_name'); ?>
<div class="input-group">
<label for="deal_description" data-error="<?php esc_attr_e('Please type description of the deal', 'wcd'); ?>"><?php _e('Deal Description', 'wcd'); ?> <span class="required">*</span></label>
<?php wp_editor($deal_description, 'deal_description'); ?>
<p class="description"><?php _e('Input description of the deal.', 'wcd'); ?></p>
</div>
How will this be achieved?
Create a new template and assign that to a page..
Now in that template copy this code :
You have to change 2 things in below code 1. YOUR_POST_TYPE , 2. YOUR
FIELD GROUP
Field group can be achieved by editing any field group (its ID will be in the top).
<?php acf_form_head(); ?>
<?php get_header(); ?>
<?php
function my_pre_save_post( $post_id )
{
// check if this is to be a new post
if( $post_id != 'new' )
{
return $post_id;
}
// Create a new post
$post = array(
'post_status' => 'publish' ,
'post_title' => $_POST['fields']['title'] ,
'post_type' => 'YOUR_POST_TYPE' ,
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
?>
<div id="content" class="clearfix row">
<div id="main" class="col-sm-12 clearfix" role="main">
<?php
acf_form(array(
'field_groups' => array('YOUR FIELD GROUP'),
'post_id' => 'new',
'submit_value' => 'Submit Product'
)); ?>
</div> <!-- end #main -->
<?php //get_sidebar(); // sidebar 1 ?>
</div> <!-- end #content -->
<?php get_footer(); ?>
I would like to change the download link title on the attachment page to say Download link : ATTACHMENT_TITLE. Where do I start? The theme has no attachment.php
EDIT :
I've found that I could edit single.php
<?php if ( is_attachment() ) { echo "Download Link : "; } ?>
<?php get_template_part( 'content', 'single' ); ?>
That puts the text above the link. It would be nice to be inline with the link. I am looking at content-single.php now. That calls a function called the_content(); If I could follow where that function goes maybe I could put the "Download Link : " text within the div itself before the link.
content-single.php
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php do_action( 'esteem_before_post_content' ); ?>
<div class="entry-content clearfix">
<?php
the_content();
$esteem_tag_list = get_the_tag_list( '', ' ', '' );
if( !empty( $esteem_tag_list ) ) {
?>
<div class="tags">
<?php
_e( 'Tagged on: ', 'esteem' ); echo $esteem_tag_list;
?>
</div>
<?php
}
wp_link_pages( array(
'before' => '<div style="clear: both;"></div><div class="pagination
clearfix">'.__( 'Pages:', 'esteem' ),
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>'
) );
?>
</div>
<div class="entry-meta-bar clearfix">
<div class="entry-meta clearfix">
<span class="icon-user"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID'
) ); ?>"><?php the_author(); ?></a></span>
<span class="icon-time"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr(
get_the_time() ); ?>"><?php the_time( get_option( 'date_format' ) ); ?></a></span>
<?php if( has_category() ) { ?>
<span class="icon-tag"><?php the_category(', '); ?></span>
<?php } ?>
<?php if ( comments_open() ) { ?>
<span class="icon-comment-alt"><?php comments_popup_link( __( 'No Comments', 'esteem' ), __(
'1 Comment', 'esteem' ), __( '% Comments', 'esteem' ), '', __( 'Comments Off', 'esteem' ) ); ?></span>
<?php } ?>
<?php edit_post_link( __( 'Edit', 'esteem' ), '<span class="icon-pencil">', '</span>' ); ?>
</div><!-- .entry-meta -->
</div><!-- .entry-meta-bar -->
<?php
do_action( 'esteem_after_post_content' );
?>
</article>
Here is the base code you can use in the page template:
<?php
$attachment_id = 1; // ID of attachment
$attachment_page = get_attachment_link( $attachment_id );
?>
Download Link**
Reference: http://codex.wordpress.org/Function_Reference/get_attachment_link
Note: If you want to modify the attachment page, you can either modify (if it exists) the attachments.php template or create one. The template hierarchy reference is here: http://codex.wordpress.org/Template_Hierarchy
EDIT:
Ok I found a simpler solution for you. On your single.php page wrap the content-single.php template part in an if statement. You can use this for the base of what you're trying to do. Give it a shot and let me know how it goes.
<?php if ( is_attachment() ) {
$attachment_link = wp_get_attachment_url();
echo 'Download Link';
} else {
get_template_part( 'content', 'single' );
} ?>
I want to stop WordPress re-ordering the category list in the admin > post edit page. The default behaviour is to take the categories assigned to the post out of their natural parent/child flow and put them at the top of the list. I want to stop this happening as it is confusing when the category structure is big.
Any thoughts?
Thanks.
While the above are great alternative solutions, especially if you want more control over the taxonomy checklist metabox, I think the simplest solution would be the following:
function taxonomy_checklist_checked_ontop_filter ($args)
{
$args['checked_ontop'] = false;
return $args;
}
add_filter('wp_terms_checklist_args','taxonomy_checklist_checked_ontop_filter');
And that should take care of that!
What version of Wordpress are you using? Wordpress 3.04 provides the Parent/Child tree on the Post Edit page. Are you sure you also aren't viewing the "Most Used" tab?
Nevermind, I see exactly the problem you are talking about, which show up after the post is saved:
Alright, try pasting this into the functions.php in your theme:
// remove the old box
function remove_default_categories_box() {
remove_meta_box('categorydiv', 'post', 'side');
}
add_action( 'admin_head', 'remove_default_categories_box' );
// add the new box
function add_custom_categories_box() {
add_meta_box('customcategorydiv', 'Categories', 'custom_post_categories_meta_box', 'post', 'side', 'low', array( 'taxonomy' => 'category' ));
}
add_action('admin_menu', 'add_custom_categories_box');
/**
* Display CUSTOM post categories form fields.
*
* #since 2.6.0
*
* #param object $post
*/
function custom_post_categories_meta_box( $post, $box ) {
$defaults = array('taxonomy' => 'category');
if ( !isset($box['args']) || !is_array($box['args']) )
$args = array();
else
$args = $box['args'];
extract( wp_parse_args($args, $defaults), EXTR_SKIP );
$tax = get_taxonomy($taxonomy);
?>
<div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
<ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
<li class="tabs"><?php echo $tax->labels->all_items; ?></li>
<li class="hide-if-no-js"><?php _e( 'Most Used' ); ?></li>
</ul>
<div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;">
<ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" >
<?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?>
</ul>
</div>
<div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
<?php
$name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']';
echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
?>
<ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
<?php
/**
* This is the one line we had to change in the original function
* Notice that "checked_ontop" is now set to FALSE
*/
wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop' => FALSE ) ) ?>
</ul>
</div>
<?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
<p><em><?php _e('You cannot modify this taxonomy.'); ?></em></p>
<?php endif; ?>
<?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
<div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children">
<h4>
<a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3">
<?php
/* translators: %s: add new taxonomy label */
printf( __( '+ %s' ), $tax->labels->add_new_item );
?>
</a>
</h4>
<p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child">
<label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label>
<input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" tabindex="3" aria-required="true"/>
<label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent">
<?php echo $tax->labels->parent_item_colon; ?>
</label>
<?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new'.$taxonomy.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $tax->labels->parent_item . ' —', 'tab_index' => 3 ) ); ?>
<input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" tabindex="3" />
<?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce-add-'.$taxonomy, false ); ?>
<span id="<?php echo $taxonomy; ?>-ajax-response"></span>
</p>
</div>
<?php endif; ?>
</div>
<?php
}
The only real change was adding 'checked_ontop' => FALSE to the args in wp_terms_checklist() function in the middle of that mess. Everything else is the original post_categories_meta_box() function.
(You could just modify the original post_categories_meta_box() in /wp-admin/includes/meta-boxes.php, but it is not recommended to mess with core and adding/removing actions as above is the proper way to do it.
There's a plugin that does just this http://wordpress.org/extend/plugins/category-checklist-tree/