基于 Woocommerce 中产品类别的条件自定义结帐字段

2024-01-25

我正在使用 woocommerce 作为一个非营利组织的网站,该网站出售课程门票和活动门票。当有人报名参加课程时,需要列出他们的紧急联系信息并同意免责。当他们购买活动门票时,非营利组织不需要紧急联系信息或责任免除。所以......他们希望这些字段仅在该人使用课程门票结帐时才出现在 woocommerce 结账上。合理?

几个月前,当他们第一次将类添加到网站时,我想出了如何添加自定义字段和自定义责任发布。我在 woocommerce 中创建了一个“class”产品类别,并创建了一个函数来测试购物车中属于该类别的任何产品,这样我就可以有条件地显示这些字段。

所有这些函数都在我的functions.php 文件中,我现在正在运行条件语句来检查每个函数中的“类”类别。我需要帮助学习如何检查“类”类别一次,然后运行显示字段的函数,验证字段,将数据添加到数据库并生成新的订单电子邮件。合理?

这是我目前所拥有的:

// Add fields for Emergency Contact & Medical Information to the checkout page
add_action('woocommerce_after_order_notes', 'customise_checkout_field');

function customise_checkout_field($checkout)
{

    // Check to see if there is a class in the cart
    // function is at the end
    $class_in_cart = is_conditional_product_in_cart( 'class' );

    // There is a class in the cart so show additional fields
    if ( $class_in_cart === true ) {

    echo '<div id="customise_checkout_field"><h3>' . __('Emergency Contact & Medical Information') . '</h3>';
    woocommerce_form_field('emergency_contact', array(
        'type' => 'text',
        'class' => array(
            'emergency-contact form-row-wide'
        ) ,
        'label' => __('Emergency Contact') ,
        'placeholder' => __('Please enter first & last name') ,
        'required' => true,
    ) , $checkout->get_value('emergency_contact'));
    woocommerce_form_field('emergency_contact_relationship', array(
        'type' => 'text',
        'class' => array(
            'emergency-contact-relationship form-row-wide'
        ) ,
        'label' => __('What is your relationship with this person?') ,
        'placeholder' => __('Example: Mother') ,
        'required' => true,
    ) , $checkout->get_value('emergency_contact_relationship'));
    woocommerce_form_field('emergency_contact_phone', array(
        'type' => 'text',
        'class' => array(
            'emergency-contact-phone form-row-wide'
        ) ,
        'label' => __('What is their phone number?') ,
        'placeholder' => __('(555) 555-5555') ,
        'required' => true,
    ) , $checkout->get_value('emergency_contact_phone'));
    woocommerce_form_field('medical_medicine', array(
        'type' => 'textarea',
        'class' => array(
            'medical-medicine form-row-wide'
        ) ,
        'label' => __('Do you have any medical conditions and are you taking any medications we need to be aware of?') ,
        'placeholder' => __('If not please write in "none"') ,
        'required' => true,
    ) , $checkout->get_value('medical_medicine'));
    echo '</div>';
    }
}

// Process emergency contact fields

add_action('woocommerce_checkout_process', 'custom_checkout_fields_process');

function custom_checkout_fields_process() {
    // Check to see if there is a class in the cart
    $class_in_cart = is_conditional_product_in_cart( 'class' );

    // There is a class in the cart so show additional fields
    if ( $class_in_cart === true ) {

        // if the field is set, if not then show an error message.
        if (!$_POST['emergency_contact']) wc_add_notice(__('Please list an emergency contact.') , 'error');
        if (!$_POST['emergency_contact_relationship']) wc_add_notice(__('Please indicate your relationship with your emergency contact.') , 'error');
        if (!$_POST['emergency_contact_phone']) wc_add_notice(__('Please list a phone number for your emergency contact.') , 'error');
        if (!$_POST['medical_medicine']) wc_add_notice(__('Please list any medications or write in "none".') , 'error');
    }
}

// Add emergency contact information to the database

add_action('woocommerce_checkout_update_order_meta', 'custom_checkout_fields_update_order_meta');

function custom_checkout_fields_update_order_meta($order_id) {
    // Check to see if there is a class in the cart
    $class_in_cart = is_conditional_product_in_cart( 'class' );

    // There is a class in the cart so show additional fields
    if ( $class_in_cart === true ) {
        if (!empty($_POST['emergency_contact'])) {
            update_post_meta($order_id, 'emergency_contact', sanitize_text_field($_POST['emergency_contact']));
        }
        if (!empty($_POST['emergency_contact_relationship'])) {
            update_post_meta($order_id, 'emergency_contact_relationship', sanitize_text_field($_POST['emergency_contact_relationship']));
        }
        if (!empty($_POST['emergency_contact_phone'])) {
            update_post_meta($order_id, 'emergency_contact_phone', sanitize_text_field($_POST['emergency_contact_phone']));
        }
        if (!empty($_POST['medical_medicine'])) {
            update_post_meta($order_id, 'medical_medicine', sanitize_text_field($_POST['medical_medicine']));
        }
    }
}

// Add the emergency contact fields to order email

add_filter( 'woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys' );
function my_custom_checkout_field_order_meta_keys( $keys ) {
    // Check to see if there is a class in the cart
    $class_in_cart = is_conditional_product_in_cart( 'class' );

    // There is a class in the cart so show additional fields
    if ( $class_in_cart === true ) {
        echo '<h2>Emergency Contact & Medical Information:</h2>';
        $keys['Emergency Contact'] = 'emergency_contact';
        $keys['Emergency Contact Relationship'] = 'emergency_contact_relationship';
        $keys['Emergency Contact Phone'] = 'emergency_contact_phone';
        $keys['Medical Conditions & Medications'] = 'medical_medicine';
        return $keys;
    } // end class in cart condition
}

/*-----------------------------------------------------------------------------------------------------------------------------------------------*/

// Add custom checkboxes to woocommerce checkout page for Photo Release, Mailing List & Release of Liability
// add_action( 'woocommerce_after_order_notes', 'custom_checkout_fields' );
add_action( 'woocommerce_review_order_before_submit', 'custom_checkout_fields' );
function custom_checkout_fields() {
    echo '<div id="custom_checkout_fields">
    <h3>Mailing Lists</h3>
    <p>Mailing List boilerplate';

    woocommerce_form_field( 'mailing_consent', array(
        'type'      => 'checkbox',
        'class'     => array('input-checkbox'),
        'label'     => __('Please add me to Nonprofit\'s electronic and paper mailing lists.'),
        'required'  => false,
        'clear'     => true,
        'default'   => 1 //This will pre-select the checkbox
    ),  WC()->checkout->get_value( 'mailing_consent' ) );

    // Check to see if there is a class in the cart
    $class_in_cart = is_conditional_product_in_cart( 'class' );

    // There is a class in the cart so show additional fields
    if ( $class_in_cart === true ) {

        echo '<h3>Photo Release</h3>
        <p>Photo Release Boilerplate</p>';

        woocommerce_form_field( 'photo_consent', array(
            'type'      => 'checkbox',
            'class'     => array('input-checkbox'),
            'label'     => __('I agree to the Photo Release as outlined above.'),
            'required'  => false,
            'clear'     => true,
            'default'   => 1 //This will pre-select the checkbox
        ),  WC()->checkout->get_value( 'photo_consent' ) );

        echo '<h3>Release of Liability</h3>
        <p>Release of Liability Boilerplate</p>';

        woocommerce_form_field( 'liability_release', array(
            'type'      => 'checkbox',
            'class'     => array('input-checkbox'),
            'label'     => __('I agree to the Photo Release as outlined above.'),
            'required'  => true,
            'clear'     => true,
            'default'   => 1 //This will pre-select the checkbox
        ),  WC()->checkout->get_value( 'liability_release' ) );

    } // end class in cart condition

    echo '</div>';
}

// Show notice if customer doesn't check the Release of Liability checkbox
add_action( 'woocommerce_checkout_process', 'liability_release_not_given' );

function liability_release_not_given() {
    // Check to see if there is a class in the cart
    $class_in_cart = is_conditional_product_in_cart( 'class' );

    // There is a class in the cart so show additional fields
    if ( $class_in_cart === true ) {
        if ( ! (int) isset( $_POST['liability_release'] ) ) {
            wc_add_notice( __( 'You must agree to the Release of Liability to register for this class.  Please contact us with any questions.' ), 'error' );
        }
    } // end class in cart condition
}

// Save the custom checkout field in the order meta, when checkbox has been checked
add_action( 'woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta', 10, 1 );
function custom_checkout_field_update_order_meta( $order_id ) {

    if ( ! empty( $_POST['mailing_consent'] ) )
        update_post_meta( $order_id, 'mailing_consent', $_POST['mailing_consent'] );

    if ( ! empty( $_POST['photo_consent'] ) )
        update_post_meta( $order_id, 'photo_consent', $_POST['photo_consent'] );

    if ( ! empty( $_POST['liability_release'] ) )
        update_post_meta( $order_id, 'liability_release', $_POST['liability_release'] );
}

/*-----------------------------------------------------------------------------------------------------------------------------------------------*/

// Display custom field results on the order edit page (backend)
// for various liability fields

add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_custom_field_on_order_edit_pages', 10, 1 );
function display_custom_field_on_order_edit_pages( $order ){

    $mailing_consent = get_post_meta( $order->get_id(), 'mailing_consent', true );
    if( $mailing_consent == 1 )
        echo '<p>' . $order->billing_first_name . ' ' . $order->billing_last_name . ' agreed to the be added to Nonprofit\'s mailing lists.</p>';

    $photo_consent = get_post_meta( $order->get_id(), 'photo_consent', true );
    if( $photo_consent == 1 )
        echo '<p>' . $order->billing_first_name . ' ' . $order->billing_last_name . ' agreed to the Photo Release.</p>';

    $liability_release = get_post_meta( $order->get_id(), 'liability_release', true );
    if( $liability_release == 1 )
        echo '<p>' . $order->billing_first_name . ' ' . $order->billing_last_name . ' agreed to the Release of Liability.</p>';
}


/**
 * Check if Class is In cart
 *
 * https://wordimpress.com/create-conditional-checkout-fields-woocommerce/
 * https://businessbloomer.com/woocommerce-check-product-category-cart/
 *
 * @param $product_id
 *
 * @return bool
 */
function is_conditional_product_in_cart( $category_name ) {
    //Check to see if user has a class in their cart
    global $woocommerce;

    //flag no class in cart
    $class_in_cart = false;

    foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
        $_product = $values['data'];

    //  if ( $_product->cat === $category_id ) {
        //  //class is in cart!
            //$class_in_cart = true;

        if (has_term ( $category_name, 'product_cat', $_product->get_id() ) ) {
            //class is in cart!
            $class_in_cart = true;
        }
    }

    return $class_in_cart;

}

正如你可能知道的那样,我从网络上的各种来源将其拼凑在一起,我意识到这有点混乱。目前的条件语句:

// Check to see if there is a class in the cart
$class_in_cart = is_conditional_product_in_cart( 'class' );

// There is a class in the cart so show additional fields
if ( $class_in_cart === true ) {

每个函数都会重复。我知道这效率不高,但我不知道如何解决它。我想做的是这样的:

  1. 测试“class”类别的产品
  2. 如果是“class”,则运行所有功能来显示和处理紧急联系人字段以及照片发布和责任字段发布
  3. 无论购物车中是否有“类别”,都显示“加入邮件列表”协议,并无论如何处理该字段。

我尝试将所有内容包装在另一个函数中,但这破坏了代码。也许最好将其移至插件中?

感谢您提供的任何想法和帮助。


首先,您使用的条件函数代码确实很旧、过时并且不管用当购物车商品是产品变体时(对于可变产品也是如此)。下面是紧凑且有效的条件函数......
它可以使用任何产品类别术语 ID、slug、名称或值数组:

function is_product_cat_in_cart( $categories ) {
    foreach ( WC()->cart->get_cart() as $cart_item ) {
        if (has_term ( $categories, 'product_cat', $cart_item['product_id'] ) )
            return true;
    }
    return false;
}

现在,您的其余代码有很多错误或很小的错误。

它还使用过时或已弃用的挂钩,例如:

  • woocommerce_checkout_update_order_meta取而代之的是一个非常合适的钩子。
  • woocommerce_email_order_meta_keys很长时间以来已被弃用。

您还可以将一些代码合并到相同的挂钩函数中。

您不需要到处都使用条件函数。它只是结账字段条件显示所需要的。

这是您重新访问的代码(适用于 woocommerce 版本 3 及更高版本):

// Add fields for Emergency Contact & Medical Information to the checkout page
add_action('woocommerce_after_order_notes', 'customise_checkout_field', 20, 1 );
function customise_checkout_field( $checkout ){
    $domain = 'woocommerce';

    // There is a class in the cart so show additional fields
    if ( is_product_cat_in_cart( 'class' ) ):

    echo '<div id="customise_checkout_field">
    <h3>' . __( 'Emergency Contact & Medical Information', $domain ) . '</h3>';

    woocommerce_form_field( 'emergency_contact', array(
        'type'          => 'text',
        'class'         => array( 'emergency-contact form-row-wide' ),
        'label'         => __( 'Emergency Contact', $domain ) ,
        'placeholder'   => __( 'Please enter first & last name', $domain ),
        'required'      => true,
    ), $checkout->get_value('emergency_contact') );

    woocommerce_form_field( 'emergency_contact_relationship', array(
        'type'          => 'text',
        'class'         => array( 'emergency-contact-relationship form-row-wide' ),
        'label'         => __( 'What is your relationship with this person?', $domain ),
        'placeholder'   => __( 'Example: Mother', $domain ) ,
        'required'      => true,
    ), $checkout->get_value('emergency_contact_relationship') );

    woocommerce_form_field( 'emergency_contact_phone', array(
        'type'          => 'text',
        'class'         => array( 'emergency-contact-phone form-row-wide' ),
        'label'         => __( 'What is their phone number?', $domain ),
        'placeholder'   => __( '(555) 555-5555', $domain ),
        'required'      => true,
    ), $checkout->get_value('emergency_contact_phone') );

    woocommerce_form_field( 'medical_medicine', array(
        'type'          => 'textarea',
        'class'         => array( 'medical-medicine form-row-wide' ) ,
        'label'         => __( 'Do you have any medical conditions and are you taking any medications we need to be aware of?', $domain ),
        'placeholder'   => __( 'If not please write in "none"', $domain ),
        'required'      => true,
    ) , $checkout->get_value('medical_medicine') );
    echo '</div>';

    endif;
}

// Add custom checkboxes to woocommerce checkout page for Photo Release, Mailing List & Release of Liability
add_action( 'woocommerce_review_order_before_submit', 'custom_checkout_fields' );
function custom_checkout_fields() {
    $checkout = WC()->checkout;
    $domain   = 'woocommerce';

    echo '<div id="custom_checkout_fields">
    <h3>'.__( 'Mailing Lists', $domain ).'</h3>
    <p>'.__( 'Mailing List boilerplate', $domain ).'</p>';

    woocommerce_form_field( 'mailing_consent', array(
        'type'      => 'checkbox',
        'class'     => array('input-checkbox'),
        'label'     => __( 'Please add me to Nonprofit\'s electronic and paper mailing lists.', $domain ),
        'required'  => false,
        'clear'     => true,
        'default'   => 1 //This will pre-select the checkbox
    ),  $checkout->get_value( 'mailing_consent' ) );

    // There is a class in the cart so show additional fields
    if ( is_product_cat_in_cart( 'class' ) ):

    echo '<h3>'.__( 'Photo Release', $domain ).'</h3>
    <p>'.__( 'Photo Release Boilerplate', $domain ).'</p>';

    woocommerce_form_field( 'photo_consent', array(
        'type'      => 'checkbox',
        'class'     => array('input-checkbox'),
        'label'     => __( 'I agree to the Photo Release as outlined above.', $domain ),
        'required'  => false,
        'clear'     => true,
        'default'   => 1 //This will pre-select the checkbox
    ),  $checkout->get_value( 'photo_consent' ) );

    echo '<h3>'.__( 'Release of Liability', $domain ).'</h3>
    <p>'.__( 'Release of Liability Boilerplate', $domain ).'</p>';

    woocommerce_form_field( 'liability_release', array(
        'type'      => 'checkbox',
        'class'     => array('input-checkbox'),
        'label'     => __( 'I agree to the Photo Release as outlined above.', $domain ),
        'required'  => true,
        'clear'     => true,
        'default'   => 1 //This will pre-select the checkbox
    ),  $checkout->get_value( 'liability_release' ) );

    endif;

    echo '</div>';
}

// Custom checkout fields validation
add_action('woocommerce_checkout_process', 'custom_checkout_fields_process');
function custom_checkout_fields_process() {
    $domain = 'woocommerce';

    if ( isset($_POST['emergency_contact']) && empty($_POST['emergency_contact']) )
        wc_add_notice( __( 'Please list an emergency contact.', $domain ) , 'error' );

    if ( isset($_POST['emergency_contact_relationship']) && empty($_POST['emergency_contact']) )
        wc_add_notice( __( 'Please indicate your relationship with your emergency contact.', $domain ), 'error' );

    if ( isset($_POST['emergency_contact_phone']) && empty($_POST['emergency_contact']) )
        wc_add_notice( __( 'Please list a phone number for your emergency contact.', $domain ), 'error' );

    if ( isset($_POST['medical_medicine']) && empty($_POST['emergency_contact']) )
        wc_add_notice( __( 'Please list any medications or write in "none".', $domain ), 'error' );

    // Other checkout fields
    if ( ! isset( $_POST['liability_release'] ) && ! $_POST['liability_release'] && isset($_POST['photo_consent']) )
        wc_add_notice( __( 'You must agree to the Release of Liability to register for this class.  Please contact us with any questions.', $domain ), 'error' );
}

// Save custom checkout fields in the order meta data
add_action( 'woocommerce_checkout_create_order', 'custom_checkout_fields_in_order_meta_data', 20, 2 );
function custom_checkout_fields_in_order_meta_data( $order, $data ) {

    if ( isset($_POST['emergency_contact']) && ! empty($_POST['emergency_contact']) )
        $order->update_meta_data( 'emergency_contact', sanitize_text_field($_POST['emergency_contact']) );

    if ( isset($_POST['emergency_contact_relationship']) && ! empty($_POST['emergency_contact_relationship']) )
        $order->update_meta_data( 'emergency_contact_relationship', sanitize_text_field($_POST['emergency_contact_relationship']) );

    if ( isset($_POST['emergency_contact_phone']) && ! empty($_POST['emergency_contact_phone']) )
        $order->update_meta_data( 'emergency_contact_phone', sanitize_text_field($_POST['emergency_contact_phone']) );

    if ( isset($_POST['medical_medicine']) && ! empty($_POST['medical_medicine']) )
        $order->update_meta_data( 'medical_medicine', sanitize_text_field($_POST['medical_medicine']) );

    if ( isset($_POST['mailing_consent']) && ! empty($_POST['mailing_consent']) )
        $order->update_meta_data( 'mailing_consent', '1' );

    if ( isset( $_POST['photo_consent']) && ! empty($_POST['photo_consent']) )
        $order->update_meta_data( 'photo_consent', '1' );

    if ( isset( $_POST['liability_release']) && ! empty($_POST['liability_release']) )
        $order->update_meta_data( 'liability_release', '1' );
}

// Add the emergency contact fields to email notifications
add_filter( 'woocommerce_email_order_meta_fields', 'custom_checkout_field_email_order_meta', 20, 3 );
function custom_checkout_field_email_order_meta( $fields, $sent_to_admin, $order ) {
    $domain = 'woocommerce';

    if( ! $order->get_meta( 'emergency_contact' ) )
        return $fields; // Exit if not set in the order

    echo '<h2>'.__( 'Emergency Contact & Medical Information', $domain ).'</h2>';

    $fields[] = array( 'label' => __( 'Emergency contact', $domain ),
        'value' => $order->get_meta( 'emergency_contact' ) );

    $fields[] = array( 'label' => __( 'Emergency Contact Relationship', $domain ),
        'value' => $order->get_meta( 'emergency_contact_relationship' ) );

    $fields[] = array( 'label' => __( 'Emergency Contact Phone', $domain ),
        'value' => $order->get_meta( 'emergency_contact_phone' ) );

    $fields[] = array( 'label' => __( 'Medical Conditions & Medications', $domain ),
        'value' => $order->get_meta( 'medical_medicine' ) );

    return $fields;
}

// Display some custom checkout fields in Order edit pages
add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_custom_field_on_order_edit_pages', 20, 1 );
function display_custom_field_on_order_edit_pages( $order ){
    $domain = 'woocommerce';

    $billing_name = $order->get_billing_first_name().' '.$order->get_billing_last_name();

    if( $order->get_meta('mailing_consent') )
        echo '<p>' . $billing_name . __( ' agreed to the be added to Nonprofit\'s mailing lists.', $domain ).'</p>';

    if( $order->get_meta('photo_consent') )
        echo '<p>' . $billing_name . __( ' agreed to the Photo Release.', $domain ).'</p>';

    if( $order->get_meta('liability_release') )
        echo '<p>' . $billing_name . __( ' agreed to the Release of Liability.', $domain ).'</p>';
}

代码位于活动子主题(或活动主题)的 function.php 文件中。经过测试并有效。

结论:如果某些代码在 function.php 文件中不起作用,那么它在插件中也不会更好地工作。但如果您愿意,可以将其添加到插件中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

基于 Woocommerce 中产品类别的条件自定义结帐字段 的相关文章

  • Magento 中的子域 htaccess 问题

    public html www domain com public html subdomain subdomain domain com public html htaccess public html subdomain htacces
  • 压缩 zend Framework 2 的 html 输出

    我目前正在 PHP 5 4 4 上使用 Zend Framework 2 beta 开发个人 web 应用程序以用于自学目的 我想知道是否可以在 html 输出发送到浏览器之前拦截它 以便通过删除所有不必要的空格来缩小它 我怎样才能在ZF2
  • Laravel 5.1 中的VerifyCsrfToken.php 第 53 行:(Firefox 浏览器)中出现 TokenMismatchException?

    我试图找出为什么会出现这个错误 即使它是全新安装的 我在我的项目中遇到了这个错误 所以我用谷歌搜索 没有一个答案对我有用 所以我创建了新项目并复制了所有控制器 视图和模型 几个小时后工作正常 再次出现令牌不匹配错误 为什么在 laravel
  • 私人聊天系统MYSQL查询显示发送者/接收者的最后一条消息

    在这里我延伸一下我之前的问题 私人聊天系统MYSQL查询ORDERBY和GROUPBY https stackoverflow com questions 10929366 private chat system mysql query o
  • PHP解析xml文件错误

    我正在尝试使用 simpleXML 来获取数据http rates fxcm com RatesXML http rates fxcm com RatesXML Using simplexml load file 我有时会遇到错误 因为这个
  • 在 PHP 中将 CSV 写入不带括号的文件

    是否有本机函数或实体类 库用于将数组写入 CSV 文件中的一行而无需封装 fputcsv将默认为 如果没有为封装参数传入任何内容 谷歌让我失望了 返回一大堆有关的页面的结果 fputcsv PEAR 的库做的事情或多或少与fputcsv 工
  • 按类别 ID 获取产品

    我正在为 woocommerce 编写一个定价表插件 用户插入带有 woocommerce 产品类别 ID 的短代码 更新页面后 用户可以看到一个包含产品名称和价格列表的表格 我怎样才能获得带有类别ID的产品列表 在下面的代码中 pid是用
  • 如何在MAMP中设置环境变量?

    如何在 MAMP 版本 3 3 中设置环境变量 我可以在我的 PHP 应用程序中使用它 我已经更新了 Applications MAMP Library bin envvars and envvars std file并添加以下行 Lice
  • 具有动态表单名称的 form_widget

    在我的 Twig 模板中 我有一个 FOR 循环 它创建多个表单 如下所示 for thing in things set form id myform thing Id set form name attribute form myfor
  • 如何从导出的 csv 文件中删除双引号

    我正在使用 Laravel 5 8 并且添加了 Maatwebsite 包 用于从数据库表导出 CSV 文件 这是我导出的类 class ConfirmedExport implements FromCollection WithHeadi
  • php - 我应该加密电子邮件地址吗?

    当用户注册时 我应该将他们的电子邮件按原样存储在数据库中还是对其进行哈希处理 我希望稍后能够解密 那么我应该使用 md5 吗 谢谢你 No md5 is 单向哈希函数 http en wikipedia org wiki Cryptogra
  • PHP 中的 Preg_replace

    我想替换 中包含的字符串中的内容content 它是多行等 preg replace 函数应该删除整个 com 没有垫子 蒙特 尝试这个 result preg replace s replacement content subject
  • 如何将 mysql 转换为 mysqli? [复制]

    这个问题在这里已经有答案了 我厌倦了将 mysql 转换为 mysqli 但似乎收到了很多错误和警告 连接到数据库没有问题 但其余代码似乎错误 我做错了什么 sql
  • PHP 中的 NOW() 函数

    是否有 PHP 函数以与 MySQL 函数相同的格式返回日期和时间NOW 我知道如何使用date 但我想问是否有专门用于此的功能 例如 返回 2009 12 01 00 00 00 您可以使用date https www php net m
  • 在 Woocommerce 购物车中设置最小小计金额

    我正在尝试将最低订单金额设置为 25 美元 到目前为止 我找到了这段代码 如果未达到最低限度 它似乎可以阻止结账 但它使用的小计包含税费 我需要在总计中排除税费 add action woocommerce checkout process
  • 如何在 HTML / Javascript 页面中插入 PHP 下拉列表

    好吧 这是我的第二篇文章 请接受我是一个完全的新手 愿意学习 花了很多时间在各个网站上寻找答案 而且我几乎已经到达了我需要到达的地方 至少在这一点上 我有一个网页 其中有许多 javascript 函数 这些函数一起使用 google 地图
  • 通过JS Laravel访问存储目录

    有没有办法访问storage目录 该目录已经链接到publicJS 中的目录 我正在尝试制作一个上传图片的表单 验证脚本 if request gt hasFile photos marker gt photos request gt ph
  • 将数组拆分为特定数量的块

    我知道array chunk 允许将数组拆分为多个块 但块的数量根据元素的数量而变化 我需要的是始终将数组拆分为特定数量的数组 例如 4 个数组 以下代码将数组分为 3 个块 两个块各有 2 个元素 1 个块有 1 个元素 我想要的是将数组
  • 如何在php中使用preg添加html属性

    我正在寻找在 php 中编写一个脚本来扫描 html 文档并根据它找到的内容向元素添加新标记 更具体地说 我是扫描文档并为每个元素搜索CSS标记 float right left 如果找到它 它会添加align right left 基于它
  • 在 PHP 中模拟 jQuery.ajax 请求

    我必须在 PHP 中模拟 AJAX 请求 就像在 jQuery 中一样 我当前的代码在这里 原始 AJAX 调用 不得修改 ajax type POST url someFile php data data success function

随机推荐

  • 如何在Spring管理的事务中手动管理Neo4j锁

    首先我会解释为什么我要手动设置写锁 我在基于 Spring Data Neo4j 的 Web 服务应用程序中使用 Neo4j 数据库 事务由Spring管理 我只使用 Transactional注释 但是 我对特定用例有问题 这会导致数据库
  • OpenCV:使用函数 cvGoodFeaturesToTrack 时出错

    当我调用函数 cvGoodFeaturesToTrack 来查找 Harris 角时 出现以下错误 OpenCV Error Assertion failed src type CV 8UC1 src type CV 32FC1 in co
  • 创建一个新的 AnonymousType 实例

    我正在尝试创建一个 AnonymousType 实例 如下所示 new Channel g Key Channel Comment g Key Comment Count g Count 在黑暗中 NET 创建一个 AnonymousTyp
  • Haskell 中的合并排序

    我是 Haskell 的新手 我正在尝试在其中实现一些已知的算法 我已经对字符串实现了合并排序 我有点失望 我的 Haskell 实现与 C 和 Java 实现相比的性能 在我的机器 Ubuntu Linux 1 8 GHz 上 C gcc
  • Maven编译错误

    您好 我有一个可以从我的计算机构建的项目 但是我在其他环境 服务器 中遇到了这个问题 INFO ERROR BUILD ERROR INFO INFO Internal error in the plugin manager executi
  • Python Virtualenv - 没有名为 virtualenvwrapper.hook_loader 的模块

    我运行的是 Mac 操作系统 10 6 8 除了 python 2 6 之外还想安装 python 2 7 并在新的 virtualenv 中使用 python 2 7 我执行了以下步骤 我下载了 python 2 7 并安装了它 http
  • 指定函数参数类型,但不指定变量

    我以前见过这样的示例代码 class C C C foo T1 T2 C foo T1 T2 not using T1 T2 与这样的传统代码相比 class D D D bar T1 t1 T2 t2 D bar T1 t1 T2 t2
  • 如何在 R 中的 data.table 中使用自定义函数

    这是我的交易数据 它显示了从帐户进行的交易from列到帐户中to包含日期和金额信息的列 data id from to date amount
  • mollview:使用 matplotlib 颜色图并更改背景颜色

    我正在尝试在healpy mollview上使用其他颜色图 我用这段代码成功了 from healpy import mollview from pylab import arange show cm m arange 768 mollvi
  • 使用输入单元格的单元格引用? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 在单元格 K1 中 VBA 插入一个单元格引用 该引用根据 vba 代码中概述的某些条件而变化 对于此示例 假设此单元格的值为 A 13
  • 使用 Tensorflow 提高 Iris ML 模型的准确性

    我是 Python 和 ML 的初学者 我正在练习这个 Iris 数据集 以使用张量流 2 0 创建 ML 模型 我解析了 csv 并使用数据集训练了模型 在模型创建过程中 我能够获得 90 的训练准确度和 91 的验证准确度 import
  • tkinter 标签的背景颜色不会改变(python 3.4)

    我正在 python 3 4 中使用 Tkinter 制作一个小部件 由于某种原因 我无法更改标签的背景颜色默认的灰色 标签的代码是这样的 self label ttk Label master text Label Text foregr
  • Android:捕获 BLE 连接失败/断开连接?

    所以在正常情况下我能够很好地连接到 BLE 设备 我想做的是处理异常情况 例如与设备的连接失败或已建立的连接丢失 也许它被扔下悬崖或被公共汽车撞到 我正在使用 CyPress BLE 模块来测试这一点 我正在做的测试之一是断开模块的电源 然
  • 为什么 Spark 会失败并显示“检测到逻辑计划之间的 INNER join 的笛卡尔积”?

    我在用火花2 1 0 当我执行以下代码时 我从 Spark 收到错误 为什么 如何修复它 val i1 Seq a string another string last one toDF a b val i2 Seq one string
  • 为什么我的类在 Visual Studio 中默认是私有的?

    当我创建一个新的类文件时 Visual Studio 默认情况下不会将其公开 我可以改变这个吗 默认情况下 没有访问说明符的类是内部类 成员默认为私有类 这使得可见性尽可能受到限制 从而增加封装性 不假思索地公开一个新类就破坏了整个封装的想
  • 在异步循环中设置 useState 挂钩

    我对reactJs很陌生 我试图在异步循环中连接结果 但出了点问题 setState 未正确保存 当我打印它时 我可以看到它是一个空数组 我想是因为里面有一个异步调用 我该如何解决这个问题 请建议我 function App const d
  • 如何通过for循环在Rmarkdown中显示绘图图像?

    我正在处理一个列表svg打印到 html 文档 我正在使用magick包认为我愿意使用其他包 解决方案 下面的代码是我尝试渲染我的 html 文档 但是 不是渲染svg对于 html 文件 它只是将元数据打印到文档中 有没有办法克服这种行为
  • Karma:使用 WSL 中的 Windows Chrome

    我正在尝试使用 Windows 版本的 Google Chrome 从 WSL 启动 karma 在 karma conf js 中 我只使用 Chrome 浏览器 browsers Chrome 我像这样导出 CHROME BIN 环境变
  • LINQ to Entities 不支持指定的类型成员“Title”

    我在使用时遇到错误Title我的 Linq to Entity 中的属性 LINQ to 不支持指定的类型成员 Title 实体 仅初始值设定项 实体成员和实体导航 支持属性 我的查询是 var db FaraWorkspaceEntity
  • 基于 Woocommerce 中产品类别的条件自定义结帐字段

    我正在使用 woocommerce 作为一个非营利组织的网站 该网站出售课程门票和活动门票 当有人报名参加课程时 需要列出他们的紧急联系信息并同意免责 当他们购买活动门票时 非营利组织不需要紧急联系信息或责任免除 所以 他们希望这些字段仅在