Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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 在woocommerce中移动客户订单注释字段_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 在woocommerce中移动客户订单注释字段

Php 在woocommerce中移动客户订单注释字段,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,大家好,我通过搜索并找到解决方案,对我在woocommerce上的结帐进行了一些编辑 到目前为止,我已经做到了,所以我跳过购物车/购物篮,直接去结帐,并重新命名了订单记录文件。使用下面的函数代码 我正在努力解决的是如何将订单注释字段移到订单审阅上方。我知道我需要在订单审核之前使用这个woocommerce\u checkout\u,但我不确定如何使用。有什么帮助吗 add_filter('woocommerce_add_to_cart_redirect', 'themeprefix_add_to

大家好,我通过搜索并找到解决方案,对我在woocommerce上的结帐进行了一些编辑

到目前为止,我已经做到了,所以我跳过购物车/购物篮,直接去结帐,并重新命名了订单记录文件。使用下面的函数代码

我正在努力解决的是如何将订单注释字段移到订单审阅上方。我知道我需要在订单审核之前使用这个woocommerce\u checkout\u,但我不确定如何使用。有什么帮助吗

add_filter('woocommerce_add_to_cart_redirect', 'themeprefix_add_to_cart_redirect');
function themeprefix_add_to_cart_redirect() {
 global $woocommerce;
 $checkout_url = wc_get_checkout_url();
 return $checkout_url;
}

//Add New Pay Button Text
add_filter( 'woocommerce_product_single_add_to_cart_text', 'themeprefix_cart_button_text' ); 
add_filter( 'woocommerce_product_add_to_cart_text', 'themeprefix_cart_button_text' ); 

function themeprefix_cart_button_text() {
 return __( 'Add to cart & go to checkout', 'woocommerce' );
}

// Place this code in your theme's functions.php file

// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     $fields['order']['order_comments']['required'] = true;
     return $fields;
}

add_filter( 'woocommerce_checkout_fields', 'filter_checkout_fields' );

function filter_checkout_fields( $fields ) {
    $fields['order']['order_comments']['maxlength'] = 160;
    $fields['order']['order_comments']['label'] = '<h2>Personalized Message</h2>';
     $fields['order']['order_comments']['placeholder'] = 'Add message here';
    return $fields;
}
add_filter('woocommerce_add_to_cart_redirect'、'themeprefix_add_to_cart_redirect');
函数themeprefix\u add\u to\u cart\u redirect(){
全球商业;
$checkout\u url=wc\u get\u checkout\u url();
返回$checkout\u url;
}
//添加新的付款按钮文本
添加过滤器(“woocommerce\u product\u single\u add\u to\u cart\u text”、“themeprefix\u cart\u button\u text”);
添加过滤器(“woocommerce\u product\u add\u to\u cart\u text”、“themeprefix\u cart\u button\u text”);
函数themeprefix\u cart\u按钮\u text(){
return u uu('Add to cart&go to checkout','woocommerce');
}
//将此代码放在主题的functions.php文件中
//勾搭
添加_过滤器('woocommerce_checkout_fields'、'custom_override_checkout_fields');
//我们的挂钩函数-$字段通过过滤器传递!
函数自定义\覆盖\签出\字段($fields){
$fields['order']['order_comments']['required']=true;
返回$fields;
}
添加_过滤器('woocommerce_checkout_fields'、'filter_checkout_fields');
函数过滤器\签出\字段($fields){
$fields['order']['order_comments']['maxlength']=160;
$fields['order']['order_comments']['label']='Personalized Message';
$fields['order']['order_comments']['placeholder']='addmessagehere';
返回$fields;
}

LoicTheAztec是正确的。订单注释仅可通过调整Woocommerce模板进行自定义

在多个站点上,我必须从正确的模板中删除并添加以下代码。这来自默认的Woocommerce 3.x模板



Order notes不能通过钩子移除,因为它们位于Woocommerce模板
checkout/form shipping.php
…所以您需要从
checkout/form shipping.php
checkout/review Order.php
…删除整个代码块,非常感谢。我刚刚完成了模板覆盖,找到并移动了这段代码。它已经移动到我想要的地方,但我现在有了副本。如中所示,我有两个订单注释字段。覆盖包含此代码的旧模板,并删除覆盖中的代码。它应该可以工作,因为注释字段只由这段代码生成。我想是的。我将checkout/form-shipping.php和checkout/review-order.php复制到/wp-content/themes/mytheme/woocommerce/checkout/中,然后从shipping中删除上述代码并将其添加到review中。然后,该字段显示在我的站点上的正确位置,但我有两个相同的字段。请仔细检查childtheme覆盖中的表单-shipping.php。也许可以添加一些额外的HTML来确保它被使用。如果没有显示额外的html,则会使用其他模板。只需选中并使用覆盖即可。
<?php if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) : ?>

    <?php if ( ! WC()->cart->needs_shipping() || wc_ship_to_billing_address_only() ) : ?>

        <h3><?php _e( 'Additional information', 'woocommerce' ); ?></h3>

    <?php endif; ?>

    <div class="woocommerce-additional-fields__field-wrapper">
        <?php foreach ( $checkout->get_checkout_fields( 'order' ) as $key => $field ) : ?>
            <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
        <?php endforeach; ?>
    </div>

<?php endif; ?>