【问题标题】:Get Woocommerce Coupon ID on thankyou.php [duplicate]在thankyou.php上获取Woocommerce优惠券ID [重复]
【发布时间】:2020-05-27 05:24:11
【问题描述】:

我正在尝试在 Woocommerce 感谢页面上将一些订单详细信息传递给第三方。一切正常——除了获取优惠券 ID。

我错过了什么?我已经通读了this question,但没有过多地阐明主题。

似乎没有很多关于 WC 优惠券的文档...谢谢!

function goodcart_tracking( $order_id ) {

    $order = new WC_Order( $order_id );
    $order_number = $order->get_id();
    $currency = $order->get_order_currency();
    $email = $order->get_billing_email();
    $total = $order->get_total();
    $coupon = $order->get_used_coupons().implode(",",$coupons);
    $date = $order->order_date;
?>

    <script type="text/javascript">
        var params = {
            'gc_hash': 'HASH_ID',
            'customer_email': '<?php echo $email ?>',
            'order_id': '<?php echo $order_number; ?>',
            'order_amount': '<?php echo $total; ?>',
            'order_amount_type': '<?php echo $currency; ?>',
            'promo_code': '<?php echo $coupon; ?>'
        };
        iGCCpnObj = new _iGCBannerObj(params); iGCCpnObj.start();
  </script>
<?php  } 

【问题讨论】:

    标签: php wordpress woocommerce coupon


    【解决方案1】:

    假设这可以进一步帮助您

    $order = new WC_Order( $order_id );
    
    $coupons = $order->get_used_coupons();
    
    foreach( $coupons as $coupon ){
    
        // Coupon id
        $coupon_post_object = get_page_by_title($coupon, OBJECT, 'shop_coupon');
        $coupon_id          = $coupon_post_object->ID;
    
        echo $coupon_id . '<br>';
    
        // Coupon object
        $coupon_object = new WC_Coupon($coupon_id);
    
        // echo...
        echo $coupon_object->get_code() . '<br>';
        //etc...
        // view: https://docs.woocommerce.com/wc-apidocs/class-WC_Coupon.html
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-11
      • 2014-11-26
      • 1970-01-01
      • 2019-12-06
      • 2017-12-12
      • 1970-01-01
      相关资源
      最近更新 更多