【问题标题】:WooCommerce: Change remove coupon link in cartWooCommerce:更改删除购物车中的优惠券链接
【发布时间】:2020-11-15 21:03:24
【问题描述】:

我想更改购物车中的移除优惠券链接。目前是括号中的“删除”一词:[Remove]

我在cart-totals.php 模板中找到了函数wc_cart_totals_coupon_html。 而且我还找到了该函数中的链接。

$coupon_html = $discount_amount_html . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', rawurlencode( $coupon->get_code() ), defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->get_code() ) . '">' . __( '[Remove]', 'woocommerce' ) . '</a>';

我只是不知道如何更改链接部分。

如果链接出现在带有标签 (wc_cart_totals_coupon_label( $coupon );) 的表格单元格中,而不是带有折扣金额的单元格中,那就太好了。但是现在,如果我可以在第一步中更改链接,那真的很有帮助。

【问题讨论】:

    标签: php wordpress woocommerce cart coupon


    【解决方案1】:

    wc-cart-functions.php 包含在线295

    echo wp_kses( apply_filters( 'woocommerce_cart_totals_coupon_html', $coupon_html, $coupon, $discount_amount_html ), array_replace_recursive( wp_kses_allowed_html( 'post' ), array( 'a' => array( 'data-coupon' => true ) ) ) ); // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound
    

    所以要更改您可以使用的链接

    function filter_woocommerce_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
        $coupon_html = $discount_amount_html . '<a href="https://www.stackoverflow.com">My url</a>';
    
        return $coupon_html;
    }
    add_filter( 'woocommerce_cart_totals_coupon_html', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );
    

    要更改购物车中的表格单元格,您可以在35-38 行编辑cart/cart-totals.php 文件

    【讨论】:

      【解决方案2】:
      1. 根据需要尝试使用静态 url 链接。

      2. 根据 WooCommerce 标准创建代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-11-04
        • 2018-07-03
        • 2017-09-15
        • 2018-08-10
        • 2021-08-08
        • 2019-04-19
        • 2019-08-17
        相关资源
        最近更新 更多