如何在线显示Woocommerce结帐通知?

时间:2018-11-29 04:30:17

标签: php wordpress woocommerce

我试图在Woocommerce内联中显示结帐通知,该通知位于其相应字段的下方或上方。我已经尝试过此代码:

/**
 * @snippet       Add Inline Field Error Notifications @ WooCommerce Checkout
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=86570
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.1
 */

add_filter( 'woocommerce_form_field', 'bbloomer_checkout_fields_in_label_error', 10, 4 );

function bbloomer_checkout_fields_in_label_error( $field, $key, $args, $value ) {
    if ( strpos( $field, '</label>' ) !== false && $args['required'] ) {
        $error = '<span class="error" style="display:none">';
        $error .= sprintf( __( '%s is a required field.', 'woocommerce' ), $args['label'] );
        $error .= '</span>';
        $field = substr_replace( $field, $error, strpos( $field, '</label>' ), 0);
    }
    return $field;
}

及其附带的CSS:

.woocommerce-checkout p.woocommerce-invalid-required-field span.error {
    color: #e2401c;
    display: block !important;
    font-weight: bold;
}

但是它不起作用,因为在页面源代码中的任何地方都没有名为woocommerce-invalid-required-field的字段。错误消息的位置在.woocommerce-notices-wrapper .woocommerce-NoticeGroup-checkout ul上完全不同。

有什么想法吗?

0 个答案:

没有答案