- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 WooCommerce 网站中,我正在使用此插件 WooCommerce Order Cancel for Customers允许客户根据付款类型和时间延迟取消订单。但是取消按钮只出现在“woocommerce_order_details_after_order_table
”上。
我希望此取消按钮出现在“查看”按钮附近的“我的帐户”>“订单列表”中:
我试图编辑插件并添加以下代码:add_filter('woocommerce_my_account_my_orders_actions', array($this, 'order_cancel_button'), 10, 2);
但它不起作用:查看按钮不见了,取消按钮也没有显示。
这是整个代码:
<?php
/**
* Plugin Name: WooCommerce Order Cancel For Customers
* Plugin URI: https://wpmanageninja.com/plugins/order-cancel-for-customers-woocommerce
* Description: A tiny plugin that will enable customers to cancel woocommerce order within a certain amount of time.
* Version: 1.0
* Author: Techjewel
* Author URI: https://wpmanageninja.com
* Requires at least: 4.4
* Tested up to: 4.8
*
* Text Domain: wco
*
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
require_once plugin_dir_path( __FILE__ ) . 'libs/class-wco-woo-settings.php';
if ( ! class_exists( 'WCOCancelOrder' ) ) :
class WCOCancelOrder {
/**
* Eligible Order statuses for cancel
* @type array
*/
private $eligibleCancelStatuses;
/**
* New Order Status for Woocommerce Order, It must have wc prefix
* @type string
*/
private $custom_order_status_name = 'wc-customer-cancel';
/**
* Declare all the action and filter hooks
*
*/
public function init_plugin() {
add_filter("plugin_action_links_".plugin_basename(__FILE__), array($this, 'wco_plugin_settings_link') );
$cancelOrderStatus = get_option('wc_wco_settings_activate');
if($cancelOrderStatus != 'yes') {
return;
}
$eligible_order_statuses = get_option('wc_wco_settings_eligible_statuses', array());
$this->eligibleCancelStatuses = apply_filters(
'wco_eligible_cancel_order_statuses', $eligible_order_statuses
);
$this->register_custom_order_status();
add_filter('wc_order_statuses', array($this,'custom_wc_order_statuses'));
add_action('admin_head', array($this, 'cancel_order_font_icon'));
add_action('woocommerce_order_details_after_order_table', array($this, 'order_cancel_button'), 10, 1);
add_filter('woocommerce_my_account_my_orders_actions', array($this, 'order_cancel_button'), 10, 2);
add_action('wp', array($this, 'process_cancel_order'));
add_action('wco_after_order_cancel_action', array($this, 'send_email_notification_to_shop_admin'), 10, 2);
add_filter('wco_notification_email_subject', array($this, 'parse_text_with_order_fields'), 10, 2);
add_filter('wco_notification_email_body', array($this, 'parse_text_with_order_fields'), 10, 2);
}
public function wco_plugin_settings_link($links) {
$settings_link = '<a href="admin.php?page=wc-settings&tab=wco_settings">'.__('Settings', 'wco').'</a>';
array_unshift($links, $settings_link);
return $links;
}
/**
* Register New order status for Woocommerce
*
* @uses register_post_status()
*/
public function register_custom_order_status()
{
register_post_status( $this->custom_order_status_name, array(
'label' => __('Cancelled By Customer', 'wco'),
'public' => true,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'exclude_from_search' => false,
'label_count' => _n_noop( 'Cancelled By Customer <span class="count">(%s)</span>', 'Cancelled By Customers <span class="count">(%s)</span>' )
) );
}
/**
* Append newly registered order-status in woocommerce status lists
*
* @param array $order_statuses
* @return array $new_order_statuses
*/
public function custom_wc_order_statuses($order_statuses)
{
$new_order_statuses = array();
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-cancelled' === $key ) {
$new_order_statuses[$this->custom_order_status_name] = __('Cancelled By Customer', 'wco');
}
}
return $new_order_statuses;
}
/**
* Add order cancel button
*
* @uses $this->can_customer_cancel_order($order)
* @param $order
*/
public function order_cancel_button($order) {
$can_cancel = apply_filters('wco_can_customer_cancel_order', $this->can_customer_cancel_order($order), $order);
if($can_cancel) {
$cancel_url = $this->get_cancel_url($order->get_id());
do_action('wco_before_cancel_button_wrapper', $order);
?>
<div class="ico_cancel_order_wrapper">
<p><i><?php _e('', 'wco'); ?></i> <a class="button" href="<?php echo $cancel_url; ?>"><?php _e('CANCEL ORDER', 'wco');?></a></p>
</div>
<?php
do_action('wco_after_cancel_button_wrapper', $order);
}
}
public function get_cancel_url($order_id) {
$urlData = build_query(array(
'wco_order_cancel_id' => $order_id,
'_nonce' => wp_create_nonce('wco_customer_cancel_order_' . $order_id),
'action' => 'process_cancel_order'
));
return site_url().'?'.$urlData;
}
/**
* Process Cancel Order once user request to cancel
*/
public function process_cancel_order() {
if(isset($_REQUEST['wco_order_cancel_id'])) {
$order_id = $_REQUEST['wco_order_cancel_id'];
if(!wp_verify_nonce($_REQUEST['_nonce'], 'wco_customer_cancel_order_'.$order_id)) {
wp_die('Security Error, Please try again!', 'wco');
}
$order = wc_get_order($order_id);
if($this->can_customer_cancel_order($order)) {
$redirectUrl = esc_url( wc_get_endpoint_url( get_option( 'woocommerce_myaccount_orders_endpoint', 'orders' ), '', wc_get_page_permalink( 'myaccount' ) ));
$redirectUrl = apply_filters('wco_after_cancel_redirect_url', $redirectUrl , $order_id);
// cancel the order now
$order_status_change_message = __('Customer wants to cancel the order and want to get refund.', 'wco');
$order_status_change_message = apply_filters('wco_after_order_cancel_note', $order_status_change_message, $order_id);
$success_message = get_option('wc_wco_settings_cancel_success_message', __('Your order has been submitted as "Cancelled by Customer"!', 'wco'));
$success_message = apply_filters('wco_after_order_cancel_message', $success_message, $order_id);
if(!wc_has_notice($success_message)) {
wc_add_notice($success_message, 'success');
}
$order = new WC_Order($order_id);
$order->update_status($this->custom_order_status_name, $order_status_change_message);
do_action('wco_after_order_cancel_action', $order, get_current_user_id());
wp_redirect($redirectUrl);
die();
} else {
wp_die('Sorry! You can not cancel this order now!', 'wco');
}
}
}
/**
* Determine if customer can cancel a selected order
*
* @param $order
*
* @return bool
*/
private function can_customer_cancel_order($order)
{
$cancelOrderStatus = get_option('wc_wco_settings_activate');
if($cancelOrderStatus != 'yes') {
return false;
}
$cancelTimeValidityMinutes = apply_filters('wco_cancel_validity_minutes', get_option('wc_wco_settings_cancel_order_threshold_time', 0), $order);
$cancelTimeValidity = $cancelTimeValidityMinutes * 60; // in seconds
$customer_id = $order->get_customer_id();
$user_ID = get_current_user_id();
$order_timestamp_diff = strtotime(current_time('mysql')) - strtotime($order->get_date_created());
if ($cancelTimeValidity > $order_timestamp_diff && $customer_id == $user_ID && in_array($order->get_status(), $this->eligibleCancelStatuses) ) {
return true;
}
return false;
}
/**
* CSS for Cancel Order Icon
*/
public function cancel_order_font_icon()
{
echo '<style>
mark.customer-cancel:after{
font-family:WooCommerce;
speak:none;
font-weight:400;
font-variant:normal;
text-transform:none;
line-height:1;
-webkit-font-smoothing:antialiased;
margin:0;
text-indent:0;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
text-align:center;
}
mark.customer-cancel:after{
content:"\e012";
color:#ff0000;
}
</style>';
}
/**
* Send email notification to admin once the customer cancel an order
*
* @param $order
* @param $user_id
*/
public function send_email_notification_to_shop_admin($order, $user_id) {
$email_to = apply_filters('wco_notification_email', get_option('wc_wco_settings_shop_owner_email'), $order);
echo $email_to;
if(!$email_to)
return;
$email_subject = apply_filters('wco_notification_email_subject', get_option('wc_wco_settings_notification_email_subject'), $order);
$email_body = apply_filters('wco_notification_email_body', get_option('wc_wco_settings_notification_email_body'), $order);
$email_headers = array(
'Content-Type: text/html; charset=UTF-8'
);
$email_headers = apply_filters('wco_notification_email_headers', $email_headers, $order);
$mail_result = wp_mail($email_to, $email_subject, $email_body, $email_headers);
do_action('wco_after_cancel_notification_email_sent_action', $mail_result, $order);
}
/**
* Parse text with order shortcodes for email
* @param $text
* @param $order
*
* @return mixed
*/
public function parse_text_with_order_fields($text, $order) {
$replace_fields = array(
'%%order_id%%' => $order->get_id(),
'%%customer_name%%' => $order->get_billing_first_name().' '.$order->get_billing_last_name(),
'%%order_admin_url%%' => get_edit_post_link($order->get_id())
);
apply_filters('wco_parse_email_replace_fields', $replace_fields, $order);
$replaces = array_keys($replace_fields);
$replacesWith = array_values($replace_fields);
$parsed_text = str_replace($replaces, $replacesWith, $text);
return $parsed_text;
}
}
endif;
/**
* Boot this plugin
*/
function wco_boot_plugin() {
$cancelOrderClass = new WCOCancelOrder();
$cancelOrderClass->init_plugin();
if(is_admin()) {
WCO_Woo_Settings::init();
}
}
add_action('init', 'wco_boot_plugin');
最佳答案
New Update May 2018: Conditional Cancel Button on my account orders list in Woocommerce
Old Update regarding your comment: The cancel button is available 3 days (from creation date) and solved a bug issue when the cancel button is pressed (made on January 2018)
add_filter( 'woocommerce_valid_order_statuses_for_cancel', 'custom_valid_order_statuses_for_cancel', 10, 2 );
function custom_valid_order_statuses_for_cancel( $statuses, $order ){
// Set HERE the order statuses where you want the cancel button to appear
$custom_statuses = array( 'completed', 'pending', 'processing', 'on-hold', 'failed' );
// Set HERE the delay (in days)
$duration = 3; // 3 days
// UPDATE: Get the order ID and the WC_Order object
if( isset($_GET['order_id']))
$order = wc_get_order( absint( $_GET['order_id'] ) );
$delay = $duration*24*60*60; // (duration in seconds)
$date_created_time = strtotime($order->get_date_created()); // Creation date time stamp
$date_modified_time = strtotime($order->get_date_modified()); // Modified date time stamp
$now = strtotime("now"); // Now time stamp
// Using Creation date time stamp
if ( ( $date_created_time + $delay ) >= $now ) return $custom_statuses;
else return $statuses;
}
代码位于事件子主题(或主题)的 function.php 文件或任何插件文件中。
'pending'
和
'failed'
You can also use the
WC_Order
object argument in the function to set some custom conditions.See this related thread: How to get WooCommerce order details
关于php - 使用 Woo Cancel for Customers Plugin 在我的帐户订单列表中添加取消按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46263626/
我尝试编写一个有多个链接表的解决方案。现在我有另一个问题: 我想将返回的行数限制为 1000。但我想显示 ID 1-1000,下一页 1001-2000。ID可以以不规则的顺序存储在数据库中(ID 1
我已经尝试申请 Drupal 商业优惠券大约 2 天了。我已经负责验证优惠券,但目前在尝试兑换优惠券时遇到了困难。 所以在我的回调函数中,我正在调用: my_module_coupons_coupon
[问]请帮忙,比如有一个数据 tbl_user | Id | name | | 1 | Bayu | | 2 | Indra | | 3 | Rangga | tbl_data | Id | user
我在 Android 应用程序中使用的一些 Parcelable 自定义类遇到了问题,我设法以一种非常奇怪的方式解决了这个问题。 仅在少数特定情况下,我在读取 parcelable 时发生了崩溃(这让
我一直在做一个项目,我需要在数据库中存储订单列表(在本例中为食品)。 我曾尝试四处寻找存储此类列表的最佳方式,但找不到任何方法。 目前,我将数据存储在 phpMyAdmin/SQL 中,订单存储为要打
目录 1、背景简介 2、订单业务 1、订单体系 2、流程管理 2
HBase案例:客户/订单 假设HBase 用于存储客户和订单信息。有两种核心记录类型被摄取:客户记录类型和订单记录类型。 客户记录类型将包含您通常期望的所有内容: 客户编号 客户名称
C-x C-b 显示缓冲区列表。首先是自然顺序,最近使用的缓冲区在顶部,隐藏的缓冲区在底部。 在那里,我现在可以按名称、大小、模式和文件对缓冲区进行排序。但是一旦我点击了这样的选项,我就无法回到原来的
我为 Woocommerce 添加了一个新的排序选项,它将按最低价格排序。我所有的价格都存储在一个自定义属性中,连同一些其他序列化数据。我想要的是有一个回调函数来反序列化这些数据,检查最低价格并按该价
想象一下我有一张 table : ID field1 field2 --- ------- ------ 111 1 11113 112
Kotlin forEach 是按数组的实际顺序遍历数组还是有时可能按其他顺序遍历数组?我的意思是这是否总是打印 1,2,3,...9 或者它可能会打印类似 1,5,3,4,... val numbe
我在 woocommerce 3+ 上创建了 html 电子邮件模板,但我无法通过订单 ID 获取订单项。我试过这个,但对我不起作用。 get_items(); foreach
我对将我自己的内部广告与 AdMob 的广告一起展示并使用按重要性顺序设置 eCPM 值的问题感到有些困惑。 我目前只与 AdMobs 的网络一起转换一个自家广告。 从常见问题解答和 AdMob 帮助
我正在尝试构建一个电子商务数据库,但我不了解订单,产品和客户之间的关系。 有很多数据库示例,但是它们太复杂了。是否有关于可能的表和关系的更简单的解释或示例。 谢谢。 最佳答案 如果客户可以拥有多个订单
我必须对电子商务系统进行一些更改以添加一些附加信息,并希望借此机会进行一些改进并使其更加灵活。当客户下订单时,我们必须为每个订购的商品存储几项信息;例如,产品价格、运费、征收的税款、所做的任何调整。
我正在尝试新的 ASP.NET bundle 功能,但似乎无法让我的自定义排序正常工作。这是我的 JS 文件: bootstrap.js bootstrap.min.js jquery-1.7.2.i
我正在尝试以下代码,并希望获取日期之间的所有订单并打印它们 $orders = $my_query->posts; $order = wc_get_order( $order_id ); $or
我有 ORMLite 数据库对象,它有一个字段: @ForeignCollectionField(eager = true) public ForeignCollection blocks; 现在,当
除了调用 event_list_attendees 并寻呼与会者以尝试找到正确的用户匹配之外,是否有其他方法可以获取门票/订单的用户条形码 ID?这种方法会增加 eventbrite 服务器的负担,并
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 5 年前。 我制作了订单食品应用程序。当我单
我是一名优秀的程序员,十分优秀!