在我的 WooCommerce 模板上,“添加评论”功能显示在单个产品页面上,就像这个网站链接:
这对我的顾客来说似乎很难。我打算将客户视图订单页面底部的按钮“添加评论”功能移动。
因此,当客户看到订单(“已完成”状态)时,他只需“点击”这个新按钮,评论就会自动更新到他的单一产品页面上。
我想像这样自定义我的 Woocommerce 模板:
我在客户查看订单页面底部添加新按钮
beri testimoni
,代码如下:
<div class="reviews-form">
<a href="#review_form" class="element-button element-colorbox"><?php _e('Add Review', 'makery'); ?></a>
</div>
<div class="site-popups hidden">
<div id="review_form">
<div class="site-popup large">
<div class="site-form">
<?php
$commenter=wp_get_current_commenter();
$comment_form=array(
'title_reply' => '',
'title_reply_to' => '',
'comment_notes_before' => '',
'comment_notes_after' => '',
'fields' => array(
'author' => '<div class="column fourcol static"><label for="author">'.__('Name', 'makery').'</label></div><div class="eightcol column static last"><div class="field-wrap"><input id="author" name="author" type="text" value="'.esc_attr($commenter['comment_author']).'" size="30" aria-required="true" /></div></div>',
'email' => '<div class="column fourcol static"><label for="email">'.__('Email', 'makery').'</label></div><div class="eightcol column static last"><div class="field-wrap"><input id="email" name="email" type="text" value="'.esc_attr($commenter['comment_author_email']).'" size="30" aria-required="true" /></div></div>',
),
'label_submit' => __('Kirim', 'makery'),
'name_submit' => 'submit',
'class_submit' => '',
'logged_in_as' => '',
'comment_field' => '',
);
if(get_option('woocommerce_enable_review_rating')=== 'yes'){
$comment_form['comment_field']='<div class="column fourcol static"><label for="rating">'.__('Rating', 'makery').'</label></div>
<div class="column eightcol static last"><div class="element-select"><span></span>
<select name="rating" id="rating">
<option value="">–</option>
<option value="5">'.__('Puas!', 'makery').'</option>
<option value="4">'.__('Keren, tapi...', 'makery').'</option>
<option value="3">'.__('Bagus', 'makery').'</option>
<option value="2">'.__('Lumayan, tapi...', 'makery').'</option>
<option value="1">'.__('Jelek!', 'makery').'</option>
</select></div></div><div class="clear"></div>';
}
$comment_form['comment_field'].= '<textarea id="comment" name="comment" cols="45" rows="6" aria-required="true" placeholder="'.__('Review', 'makery').'"></textarea>';
comment_form(apply_filters('woocommerce_product_review_comment_form_args', $comment_form));
?>
</div>
</div>
</div>
</div>
<!-- /popups -->
注:此代码与单品页面“添加评论”代码相同
但是,这会产生一些错误,并且 不起作用...
我做错了什么?
我该如何解决?
谢谢
将上面的代码粘贴到functions.php文件中。它将在您的订单历史记录页面上创建一个评论按钮:https://my-domain/my-account/orders
function custom_add_review_link_to_my_account( $actions, $order ) {
if ( ! $order || ! is_user_logged_in() ) {
return $actions;
}
$order_id = $order->get_id();
$order_status = $order->get_status();
$reviewed = get_post_meta( $order_id, '_reviewed', true );
if ( $order_status === 'completed' && ! $reviewed ) {
$items = $order->get_items();
$product_id = 0;
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
break;
}
$product_url = get_permalink( $product_id );
if ( $product_url ) {
$actions['review'] = array(
'url' => $product_url . '#reviews',
'name' => '★★★★★',
);
}
}
return $actions; } add_filter( 'woocommerce_my_account_my_orders_actions', 'custom_add_review_link_to_my_account', 10, 2 );