按下按钮时,插件中的什么导致“白屏死机”?

时间:2019-06-14 11:46:54

标签: wordpress woocommerce storefront

我最近完成了自己的代码混合和匹配插件,以处理WooCommerce网站上的表格(使其更适合于购买sutff的公司)。它可以在本地正常运行,但是当我将其放在现场的网站上时,使用链接/按钮将您定向到其他页面(网站上)时,我会白屏死机-我不知道为什么!有什么想法吗?

我真的没有尝试过任何东西,因为我对woocommerce,wordpress和PHP的了解最多...初学者。

插件:

/*
 * Plugin Name: Posifon Form Management Plugin
 */
defined('ABSPATH') or die('No script kiddies please!');

/* === GENERAL === */
/* Add new fields */
add_filter( 'woocommerce_checkout_fields' , 'plugin_add_custom_billing_fields' );
function plugin_add_custom_billing_fields($fields) {
    $fields['billing']['billing_org_number'] = array(
        'label'     => __('Organisationsnummer', 'woocommerce'),
        'placeholder'   => __('T.ex. 1234-5678', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true,
    );

    $fields['billing']['billing_org_reference'] = array(
        'label'     => __('Kostnadsställe/referens', 'woocommerce'),
        'placeholder'   => __('T.ex. Per Olofsson', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true,
    );

    return $fields;
}

/* Save fields to database */
function reigel_woocommerce_checkout_update_user_meta( $customer_id, $posted) {
    if (isset($posted['billing_org_number'])) {
        $dob = sanitize_text_field( $posted['billing_org_number'] );
        update_user_meta( $customer_id, 'billing_org_number', $dob);
    }

    if (isset($posted['billing_org_reference'])) {
        $dob = sanitize_text_field( $posted['billing_org_reference'] );
        update_user_meta( $customer_id, 'billing_org_reference', $dob);
    }
}
add_action( 'woocommerce_update_user_meta', 'reigel_woocommerce_checkout_update_user_meta', 10, 2 );

/* === MY ACCOUNT / EDIT ADRESSES / BILLING === */
/* Override default fields */
add_filter( 'woocommerce_billing_fields', 'plugin_override_account_billing', 20, 1 );
function plugin_override_account_billing( $fields ) {
    // Only on my account 'edit-address'
    if( is_wc_endpoint_url( 'edit-address' ) ){
        // Company
        $fields['billing_company']['required'] = true;
        $fields['billing_company']['label'] = 'Organisation';
        // Organisation Number
        $fields['billing_org_number']['label'] = 'Organisationsnummer';
        $fields['billing_org_number']['required'] = true;
        // Organisation Reference
        $fields['billing_org_reference']['label'] = 'Kostnadsställe/referens';
        $fields['billing_org_reference']['required'] = true;
        // Put City and Postcode on same row
        $fields['billing_postcode']['class'][0] = 'form-row-first';
        $fields['billing_city']['class'][0] = 'form-row-last';
    }
    return $fields;
}

/* Change order of BILLING */
add_filter( 'woocommerce_billing_fields', 'plugin_change_order_account_billing', 20, 1 );
function plugin_change_order_account_billing( $fields ) {
    // Only on my account 'edit-address'
    if( is_wc_endpoint_url( 'edit-address' ) ){
        $fields['billing_company']['priority'] = 10;
        $fields['billing_org_number']['priority'] = 20;
        $fields['billing_org_reference']['priority'] = 30;
        $fields['billing_address_1']['priority'] = 40;
        $fields['billing_address_2']['priority'] = 50;
        $fields['billing_postcode']['priority'] = 60;
        $fields['billing_city']['priority'] = 70;
        $fields['billing_country']['priority'] = 80;
        $fields['billing_first_name']['priority'] = 90;
        $fields['billing_last_name']['priority'] = 100;
        $fields['billing_phone']['priority'] = 110;
        $fields['billing_email']['priority'] = 120;
    }
    return $fields;
}

/* === MY ACCOUNT / EDIT ADRESSES / SHIPPING === */
/* Override default fields */
add_filter( 'woocommerce_shipping_fields', 'plugin_override_account_shipping', 20, 1 );
function plugin_override_account_shipping( $fields ) {
    // Only on my account 'edit-address'
    if( is_wc_endpoint_url( 'edit-address' ) ){
        // Company
        $fields['shipping_company']['required'] = true;
        $fields['shipping_company']['label'] = 'Organisation';
        // Put City and Postcode on same row
        $fields['shipping_postcode']['class'][0] = 'form-row-first';
        $fields['shipping_city']['class'][0] = 'form-row-last';

        unset($fields['shipping_first_name']);
        unset($fields['shipping_last_name']);
    }
    return $fields;
}

/* Change order of BILLING */
add_filter( 'woocommerce_shipping_fields', 'plugin_change_order_account_shipping', 20, 1 );
function plugin_change_order_account_shipping( $fields ) {
    // Only on my account 'edit-address'
    if( is_wc_endpoint_url( 'edit-address' ) ){
        $fields['shipping_company']['priority'] = 10;
        $fields['shipping_address_1']['priority'] = 20;
        $fields['shipping_address_2']['priority'] = 30;
        $fields['shipping_postcode']['priority'] = 40;
        $fields['shipping_city']['priority'] = 50;
        $fields['shipping_country']['priority'] = 70;
    }
    return $fields;
}

/* === CHECKOUT / BILLING === */
/* Override default fields */
add_filter('woocommerce_checkout_fields', 'plugin_override_default_billing_fields');
function plugin_override_default_billing_fields($fields) {
    $fields['billing']['billing_company']['required'] = true;
    $fields['billing']['billing_postcode']['class'][0] = 'form-row-first';
    $fields['billing']['billing_city']['class'][0] = 'form-row-last';

    return $fields;
}

/* Change order of billing CHECKOUT */
add_filter("woocommerce_checkout_fields", "plugin_override_order_checkout_fields");
function plugin_override_order_checkout_fields($fields) {
    $order = array(
        'billing_first_name',
        'billing_last_name',
        'billing_company',
        'billing_email',
        'billing_phone',
        'billing_country',
        'billing_address_1',
        'billing_address_2',
        'billing_city',
        'billing_postcode',
        'billing_org_number',
        'billing_org_reference'
    );

    foreach($order as $field) {
        $ordered_fields[$field] = $fields['billing'][$field];
    };

    $fields['billing'] = $ordered_fields;

    $fields['billing']['billing_company']['priority'] = 10;
    $fields['billing']['billing_org_number']['priority'] = 20;
    $fields['billing']['billing_org_reference']['priority'] = 30;
    $fields['billing']['billing_address_1']['priority'] = 40;
    $fields['billing']['billing_address_2']['priority'] = 50;
    $fields['billing']['billing_postcode']['priority'] = 60;
    $fields['billing']['billing_city']['priority'] = 70;
    $fields['billing']['billing_country']['priority'] = 80;
    $fields['billing']['billing_first_name']['priority'] = 100;
    $fields['billing']['billing_last_name']['priority'] = 110;
    $fields['billing']['billing_email']['priority'] = 130;
    $fields['billing']['billing_phone']['priority'] = 140;


    return $fields;
}

/* === CHECKOUT / SHIPPING === */
/* Override default fields */
add_filter('woocommerce_checkout_fields', 'plugin_override_default_shipping_fields');
function plugin_override_default_shipping_fields($fields) {
    // Company
    $fields['shipping']['shipping_company']['required'] = true;
    $fields['shipping']['shipping_company']['label'] = 'Organisation';
    // Put City and Postcode on same row
    $fields['shipping']['shipping_postcode']['class'][0] = 'form-row-first';
    $fields['shipping']['shipping_city']['class'][0] = 'form-row-last';
    // Remove first- and last name
    unset($fields['shipping']['shipping_first_name']);
    unset($fields['shipping']['shipping_last_name']);

    return $fields;
}

/* Change order of billing CHECKOUT */
add_filter("woocommerce_checkout_fields", "plugin_override_order_checkout_shipping_fields");
function plugin_override_order_checkout_shipping_fields($fields) {
    $order = array(
        'shipping_company',
        'shipping_country',
        'shipping_address_1',
        'shipping_address_2',
        'shipping_city',
        'shipping_postcode',
    );

    foreach($order as $field) {
        $ordered_fields[$field] = $fields['shipping'][$field];
    };

    $fields['shipping'] = $ordered_fields;

    $fields['shipping']['shipping_company']['priority'] = 10;
    $fields['shipping']['shipping_address_1']['priority'] = 40;
    $fields['shipping']['shipping_address_2']['priority'] = 50;
    $fields['shipping']['shipping_postcode']['priority'] = 60;
    $fields['shipping']['shipping_city']['priority'] = 70;
    $fields['shipping']['shipping_country']['priority'] = 80;


    return $fields;
}

/* === MY ACCOUNT === */
/* Override default fields */
add_filter('woocommerce_billing_fields', 'plugin_override_default_account_fields');
function plugin_override_default_account_fields($fields) {
    if( is_user_logged_in() && is_account_page() ) {
        unset($fields['account_first_name']);
        unset($fields['account_last_name']);
    }
    return $fields;
}

/* === DISPLAYING === */
/* Display field value on the order edit page ADMIN */
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'plugin_checkout_field_display_admin_order_meta', 10, 1 );
function plugin_checkout_field_display_admin_order_meta($order) {
    echo '<p><strong>'.__('Organisationsnummer').':</strong> ' . get_post_meta( $order->get_id(), '_billing_org_number', true ) . '</p>';
    echo '<p><strong>'.__('Kostnadsställe/referens').':</strong> ' . get_post_meta( $order->get_id(), '_billing_org_reference', true ) . '</p>';
}

需要更多代码,我将对其进行编辑并将其提供给您,我还对my-address.php(woocommerce文件)做了一些更改。

我想要的结果:不会出现死亡白屏。

编辑:我试图为PHP添加更多内存,但没有用。

2 个答案:

答案 0 :(得分:2)

在您的wp_config.php中(在网站的根目录中),您可能有以下一行:

define('WP_DEBUG', false);

将此更改为:

define('WP_DEBUG', true);

并再次检查您的死亡白屏-它应该向您显示哪个文件以及该文件中的哪一行,发生了错误:-)

答案 1 :(得分:1)

感谢rblarsens回答,我发现了错误:

  

警告::无法修改标头信息-标头已由...发送

这仅仅是由第一个空格之前的空格(“”)引起的