【发布时间】:2017-12-21 07:04:12
【问题描述】:
我想将我在 WooCommerce 管理仪表板小部件中的默认状态更改为插件订单状态管理器中的自定义状态。
第一步
所以我在 WooCommerce 的文档中找到了 status_widget_order_rows 钩子代码,并将其添加到我的 functions.php 中,我将所有默认状态替换为
我的自定义状态 'needs changes' = wc-change 和 'waiting for approval' = wc-waiting。我保存了它,但什么也没发生。
第二步
我以为当我移除钩子并用我的自定义钩子替换它时,它会显示出来,但这并没有发生。
三付
我以为当我在我的 functions.php 中手动添加状态时,然后挂钩到它将显示的状态,但事实并非如此。
function custom_remove_status_widget_order_rows() {
remove_action('WC_Admin_Dashboard', 'status_widget_order_rows' );
add_action('WC_Admin_Dashboard', 'custom_status_widget_order_rows', 10, 2);}
function custom_status_widget_order_rows() {
if ( ! current_user_can( 'edit_shop_orders' ) ) {
return;
}
$change_count = 0;
$waiting_count = 0;
foreach ( wc_get_order_types( 'order-count' ) as $type ) {
$counts = (array) wp_count_posts( $type );
$change_count += isset( $counts['wc-change'] ) ? $counts['wc-change'] : 0;
$waiting_count += isset( $counts['wc-waiting'] ) ? $counts['wc-waiting'] : 0;
}
?>
<li class="waiting-orders">
<a href="<?php echo admin_url( 'edit.php?post_status=wc-waiting&post_type=shop_order' ); ?>">
<?php
/* translators: %s: order count */
printf(
_n( '<strong>%s order</strong> waiting to be approved', '<strong>%s orders</strong> awaiting waiting', $waiting_count, 'woocommerce' ),
$waiting_count
);
?>
</a>
</li>
<li class="change-orders">
<a href="<?php echo admin_url( 'edit.php?post_status=wc-change&post_type=shop_order' ); ?>">
<?php
/* translators: %s: order count */
printf(
_n( '<strong>%s order</strong> needs changes', '<strong>%s orders</strong> are changed', $change_count, 'woocommerce' ),
$rejected_count
);
?>
</a>
</li>
<?php
}?>
最后
不知何故,我需要先从插件加载状态,然后覆盖默认的 woocommerce 类,然后添加行。
这是插件的链接 -> docs.woocommerce.com/document/woocommerce-order-status-manager/
但我是初学者 php,所以我希望有人可以帮助我吗?
提前致谢
【问题讨论】:
标签: php wordpress woocommerce