简体   繁体   English

如何修改 wordpress 插件中的付款表格?

[英]How to modify a payment form in a wordpress plugin?

I'm trying to create a food delivery web page with the wordpress restropress plugin, the page looks like this: https://restropress.magnigenie.com/demo/food-items/我正在尝试使用 wordpress retropress 插件创建食品配送 web 页面,页面如下所示: https://retropress.magnigen.com

And the problem I have is that in the checkout form I want to remove the city field since being a delivery I obviously only make deliveries in my city and I don't want my customers to go through that redundancy.我遇到的问题是,在结帐表单中,我想删除 city 字段,因为作为送货服务,我显然只在我的城市送货,我不希望我的客户通过这种冗余发送到 go。 I would also like to change the postcode field from text to a drop-down.我还想将邮政编码字段从文本更改为下拉菜单。

I have tried with some action hooks setting as "unset" the field "city" but nothing.我曾尝试将一些动作挂钩设置为“取消设置”字段“城市”,但没有。 In the html of the page I managed to make the changes directly but when I updated the plug-in changes were lost.在页面的 html 中,我设法直接进行了更改,但是当我更新插件时,更改丢失了。

Can you help me?你能帮助我吗? This is the plugins code that I'm trying to modify:这是我要修改的插件代码:

<fieldset id="rpress_checkout_order_details">
    <legend><?php echo apply_filters( 'rpress_checkout_order_details_text', esc_html__( 'Order Details', 'restropress' ) ); ?></legend>
    <?php do_action( 'rpress_purchase_form_before_order_details' ); ?>
    <?php
        if( rpress_selected_service() == 'delivery' ) :
            $customer  = RPRESS()->session->get( 'customer' );
            $customer  = wp_parse_args( $customer, array( 'delivery_address' => array(
                'address'       => '',
                'flat'          => '',
                'city'      => '',
                'postcode'  => '',
            ) ) );

            $customer['delivery_address'] = array_map( 'sanitize_text_field', $customer['delivery_address'] );

            if( is_user_logged_in() ) {

                $user_address = get_user_meta( get_current_user_id(), '_rpress_user_delivery_address', true );

                foreach( $customer['delivery_address'] as $key => $field ) {

                    if ( empty( $field ) && ! empty( $user_address[ $key ] ) ) {
                        $customer['delivery_address'][ $key ] = $user_address[ $key ];
                    } else {
                        $customer['delivery_address'][ $key ] = '';
                    }
                }
            }
            $customer['delivery_address'] = apply_filters( 'rpress_delivery_address', $customer['delivery_address'] );
    ?>
        <p id="rpress-street-address" class="rp-col-md-6 rp-col-sm-12">
            <label class="rpress-street-address" for="rpress-street-address">
                <?php esc_html_e('Street Address', 'restropress') ?>
                <span class="rpress-required-indicator">*</span>
            </label>
            <input class="rpress-input" type="text" name="rpress_street_address" id="rpress-street-address" placeholder="<?php esc_html_e('Street Address', 'restropress'); ?>" value="<?php echo $customer['delivery_address']['address']; ?>" />
        </p>
        <p id="rpress-apt-suite" class="rp-col-md-6 rp-col-sm-12">
            <label class="rpress-apt-suite" for="rpress-apt-suite">
                <?php esc_html_e('Apartment, suite, unit etc. (optional)', 'restropress'); ?>
            </label>
            <input class="rpress-input" type="text" name="rpress_apt_suite" id="rpress-apt-suite" placeholder="<?php esc_html_e('Apartment, suite, unit etc. (optional)', 'restropress'); ?>" value="<?php echo $customer['delivery_address']['flat']; ?>" />
        </p>
        <p id="rpress-city" class="rp-col-md-6 rp-col-sm-12">
            <label class="rpress-city" for="rpress-city">
                <?php _e('Town / City', 'restropress') ?>
                <span class="rpress-required-indicator">*</span>
            </label>
            <input class="rpress-input" type="text" name="rpress_city" id="rpress-city" placeholder="<?php _e('Town / City', 'restropress') ?>" value="<?php echo $customer['delivery_address']['city']; ?>" />
        </p>
        <p id="rpress-postcode" class="rp-col-md-6 rp-col-sm-12">
            <label class="rpress-postcode" for="rpress-postcode">
                <?php _e('Postcode / ZIP', 'restropress') ?>
                <span class="rpress-required-indicator">*</span>
            </label>
            <input class="rpress-input" type="text" name="rpress_postcode" id="rpress-postcode" placeholder="<?php _e('Postcode / ZIP', 'restropress') ?>" value="<?php echo $customer['delivery_address']['postcode']; ?>" />
        </p>
    <?php endif; ?>
    <p id="rpress-order-note" class="rp-col-sm-12">
    <label class="rpress-order-note" for="rpress-order-note"><?php echo sprintf( __('%s Instructions', 'restropress'), rpress_selected_service( 'label' ) ); ?></label>
    <textarea name="rpress_order_note" class="rpress-input" rows="5" cols="8" placeholder="<?php echo sprintf( __('Add %s instructions (optional)', 'restropress'), strtolower( rpress_selected_service( 'label' ) ) ); ?>"></textarea>
  </p>
    <?php do_action( 'rpress_purchase_form_order_details' ); ?>
    <?php do_action( 'rpress_purchase_form_order_details_fields' ); ?>
</fieldset>

I put this following hook in the functions.php file and it didn't work:我将以下钩子放在 functions.php 文件中,但它不起作用:

function wp_edit_checkout_fields($fields){

    unset($fields['delivery_adress']['city']);

    return $fields;

}

add_filter('rpress_purchase_form_order_details_fields', 'wp_edit_checkout_fields');

Note that, there is do_action( 'rpress_purchase_form_order_details_fields' );请注意,有do_action( 'rpress_purchase_form_order_details_fields' ); in the plugin code.在插件代码中。 It is usually used with add_action , but not with add_filter .它通常与add_action一起使用,但不与add_filter一起使用。

Maybe you could take advantage of this filter call:也许你可以利用这个过滤器调用:

$customer['delivery_address'] = apply_filters( 'rpress_delivery_address', $customer['delivery_address'] );

Try something like this (put in your function.php file):尝试这样的事情(放入您的function.php文件):

function your_custom_function($delivery_address) {
    // Try to somehow process the city field here...
    
    // First, you could output a variable
    // to understand the data structure
    print_r($delivery_address);

    // and return the changed address
    return $delivery_address;
}
add_filter( 'rpress_delivery_address', 'your_custom_function' );

Docs -https://developer.wordpress.org/reference/functions/add_filter/文档 -https://developer.wordpress.org/reference/functions/add_filter/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM