大家都是通过搜索和查找解决方案来管理我在woocommerce结帐时进行一些编辑。
到目前为止,我已经做到了这一点,所以我跳过购物车/购物篮,直接结账,并重新命名了订单备注。使用下面的功能代码。
我正在努力解决的问题是如何在订单审核之上移动订单备注字段。我知道我需要使用这个woocommerce_checkout_before_order_review,但我不知道如何。任何帮助都会很棒?
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;
}
答案 0 :(得分:0)
LoicTheAztec是对的。订单备注只能通过调整Woocommerce模板进行自定义。
在mutliple网站上,我不得不删除并将以下代码添加到正确的模板中。这来自默认的Woocommerce 3.x模板。
<?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; ?>