0

我正在尝试在 Klarna 支付插件中添加时事通讯复选框。这是实际网站的屏幕截图。

在此处输入图像描述

这是实时链接:https ://stressleksaker.se/checkout/ 这里是插件代码:https ://github.com/krokedil/klarna-checkout-for-woocommerce

我想在条款和条件复选框下方添加时事通讯,但我很难,因为此布局是由 klarna 插件生成的。

这是负责生成此 iframe 的代码段。

/**
 * Echoes Klarna Checkout iframe snippet.
 */
function kco_wc_show_snippet() {
    $klarna_order = kco_create_or_update_order();
    do_action( 'kco_wc_show_snippet', $klarna_order );
    echo $klarna_order['html_snippet'];

    
    // phpcs:ignore WordPress -- Can not escape this, since its the iframe snippet.
}

这是 kco_create_or_update_order 函数定义。

function kco_create_or_update_order( $order_id = null ) {
    // Need to calculate these here, because WooCommerce hasn't done it yet.
    WC()->cart->calculate_fees();
    WC()->cart->calculate_shipping();
    WC()->cart->calculate_totals();
    
    if ( WC()->session->get( 'kco_wc_order_id' ) ) { // Check if we have an order id.
        // Try to update the order, if it fails try to create new order.
        $klarna_order = KCO_WC()->api->update_klarna_order( WC()->session->get( 'kco_wc_order_id' ), null, true );
        if ( ! $klarna_order ) {
            // If update order failed try to create new order.
            $klarna_order = KCO_WC()->api->create_klarna_order();
            if ( ! $klarna_order ) {
                // If failed then bail.
                return;
            }
            WC()->session->set( 'kco_wc_order_id', $klarna_order['order_id'] );
            return $klarna_order;
        }
        return $klarna_order;
    } else {
        // Create new order, since we dont have one.
        $klarna_order = KCO_WC()->api->create_klarna_order();
        if ( ! $klarna_order ) {
            return;
        }
        WC()->session->set( 'kco_wc_order_id', $klarna_order['order_id'] );
        return $klarna_order;
    }
}

我试过kco_wc_show_snippet钩子来显示,但它在 Iframe 之前显示内容,但我想在 Iframe 下方的条款和条件复选框中显示时事通讯复选框。

请帮助,如果您希望我添加更多相关代码,请询问。

4

0 回答 0