【问题标题】:Issue with output of WooCommerce hooks on cart and checkout page购物车和结帐页面上的 WooCommerce 挂钩输出问题
【发布时间】:2021-08-14 17:17:28
【问题描述】:

我正在尝试在我的购物车页面上应用的优惠券下方添加一些文本,但由于某种原因,我只能将其显示在表格上方,如屏幕截图所示。

我什至创建了一个全新安装的 2020 主题,除了 woocommerce 之外没有安装其他插件。

这些是我正在使用的代码:

add_action('woocommerce_cart_totals_before_shipping', 'bb_before_shipping');
function bb_before_shipping() {
    echo 'woocommerce_cart_totals_before_shipping';
}

add_action('woocommerce_before_cart_totals', 'apply_product_on_coupon');
function apply_product_on_coupon() {
    global $woocommerce;
    if ( ! empty( $woocommerce->cart->applied_coupons ) ) {
        echo 'woocommerce_before_cart_totals';
    }       
}

任何帮助将不胜感激!

【问题讨论】:

    标签: wordpress woocommerce cart hook-woocommerce checkout


    【解决方案1】:

    您为购物车页面使用了正确的挂钩,但输出是 HTML 表格的一部分。

    所以你得到:

    // Cart
    function action_woocommerce_cart_totals_before_shipping() {
        echo '<tr><td>woocommerce_cart_totals_before_shipping</td></tr>';
    }
    add_action( 'woocommerce_cart_totals_before_shipping', 'action_woocommerce_cart_totals_before_shipping' );
    
    // Checout
    function action_woocommerce_review_order_before_shipping() {
        echo '<tr><td>woocommerce_review_order_before_shipping</td></tr>';  
    }
    add_action( 'woocommerce_review_order_before_shipping', 'action_woocommerce_review_order_before_shipping' );
    

    【讨论】:

      猜你喜欢
      • 2017-12-01
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 2018-02-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      相关资源
      最近更新 更多