Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将自定义订单状态设置为付款有效_Php_Wordpress_Woocommerce_Hook Woocommerce_Orders - Fatal编程技术网

Php 将自定义订单状态设置为付款有效

Php 将自定义订单状态设置为付款有效,php,wordpress,woocommerce,hook-woocommerce,orders,Php,Wordpress,Woocommerce,Hook Woocommerce,Orders,此函数位于类WC_Abstract_Order(核心文件)中 我需要向数组中添加一个额外的自定义订单状态,但无法为functions.php编写代码来覆盖该函数,如下所示-即仅使用添加的状态: public function needs_payment() { $valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed',

此函数位于类WC_Abstract_Order(核心文件)中

我需要向数组中添加一个额外的自定义订单状态,但无法为functions.php编写代码来覆盖该函数,如下所示-即仅使用添加的状态:

public function needs_payment() {

    $valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed','neworderstatus' ), $this );

    if ( $this->has_status( $valid_order_statuses ) && $this->get_total() > 0 ) {
        $needs_payment = true;
    } else {
        $needs_payment = false;
    }

    return apply_filters( 'woocommerce_order_needs_payment', $needs_payment, $this, $valid_order_statuses );
}
我们感激地接受了任何帮助


谢谢。

首先,您需要注册您的自定义状态(如果未完成):

代码位于活动子主题(或主题)的function.php文件或任何插件文件中

它应该像预期的那样工作



相关回答:

从WooCommerce 4.3开始,在上述回答中更改“自定义”状态“有效”支付功能中的行

// Registering the custom status as valid for payment
$statuses[] = 'wc-custom-status';


应该有用。

谢谢你的帮助。我无法将此问题标记为已解决,因为我无法将其用于我们的设置,但我没有理由相信您的代码不正确,应该适用于其他人。感谢您的帮助,最后我决定放弃该插件,并使用与您的in函数类似的代码。-我必须为第一位使用稍微不同的代码,因为它在我使用的插件中抛出了一个错误,请参阅中的该替代代码的附加答案-不确定区别是什么,但我猜这是什么..欢迎使用stackoverflow。你能提供更详细的答案吗。需要做什么以及为什么?请不要生气,请阅读:
// Register new status
add_action('init', 'register_custom_order_statuses');
function register_custom_order_statuses() {
    register_post_status('wc-custom-status', array(
        'label'                     => 'Custom Status',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop('Custom Status <span class="count">(%s)</span>', 'Custom Status <span class="count">(%s)</span>')
    ));
}

// Add to list of WC Order statuses
add_filter('wc_order_statuses', 'add_custom_order_statuses');
function add_custom_order_statuses($order_statuses) {
    $new_order_statuses = array();

    // add new order status after processing for example
    foreach ($order_statuses as $key => $status) {
        $new_order_statuses[$key] = $status;
        if ('wc-processing' === $key) {
            $new_order_statuses['wc-custom-status'] = 'Custom Status';
        }
    }
    return $new_order_statuses;
}
add_filter( 'woocommerce_valid_order_statuses_for_payment', 'custom_status_valid_for_payment', 10, 2 );
function custom_status_valid_for_payment( $statuses, $order ) {

    // Registering the custom status as valid for payment
    $statuses[] = 'wc-custom-status';

    return $statuses;
}
// Registering the custom status as valid for payment
$statuses[] = 'wc-custom-status';
// Registering the custom status as valid for payment
$statuses[] = 'custom-status';