将页面中的订单 ID 插入 wc_get_order() 函数
P粉969253139
P粉969253139 2023-09-02 14:10:45
[PHP讨论组]

我想将数据输出更改为表格。

这是表格代码:

<div class="filters">
            <form>
                <div class="filters-row">
                    <input type="hidden" class="product-search wc-product-search" name="product_id" data-placeholder="<?php esc_html_e( 'Product:', 'yith-woocommerce-affiliates' ); ?>" value="<?php echo esc_attr( $product_id ); ?>" data-selected="<?php echo esc_attr( $product_name ); ?>" />
                    <input type="text" class="datepicker" name="from" placeholder="<?php esc_html_e( 'From:', 'yith-woocommerce-affiliates' ); ?>" value="<?php echo esc_attr( $from ); ?>"/>
                    <input type="text" class="datepicker" name="to" placeholder="<?php esc_html_e( 'To:', 'yith-woocommerce-affiliates' ); ?>" value="<?php echo esc_attr( $to ); ?>"/>
                    <label for="per_page" class="per-page">
                        <?php esc_html_e( 'Items per page:', 'yith-woocommerce-affiliates' ); ?>
                        <input max="100" min="1" step="1" type="number" name="per_page" value="<?php echo esc_attr( $per_page ); ?>"/>
                    </label>
                </div>
                <div class="button-row">
                    <input type="submit" value="<?php esc_html_e( 'Filter', 'yith-woocommerce-affiliates' ); ?>"/>
                    <?php if ( $filter_set ) : ?>
                        <a href="<?php echo esc_url( $dashboard_commissions_link ); ?>"><?php esc_html_e( 'Reset', 'yith-woocommerce-affiliates' ); ?></a>
                    <?php endif; ?>
                </div>
            </form>
        </div>

        <table class="shop_table" id="table">
            <thead>
            <tr>
                <th class="column-id">
                    <a rel="nofollow" class="<?php echo ( 'ID' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?>" href="<?php echo esc_url( add_query_arg( array( 'orderby' => 'ID', 'order' => $to_order ) ) ); ?>"><?php esc_html_e( '#/ID', 'yith-woocommerce-affiliates' ); ?></a>
                </th>
                <th class="column-date">
                    <a rel="nofollow" class="<?php echo ( 'created_at' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?>" href="<?php echo esc_url( add_query_arg( array( 'orderby' => 'created_at', 'order' => $to_order ) ) ); ?>"><?php esc_html_e( 'Date', 'yith-woocommerce-affiliates' ); ?></a>
                </th>
                <th class="column-product">
                    <a rel="nofollow" class="<?php echo ( 'product_name' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?>" href="<?php echo esc_url( add_query_arg( array( 'orderby' => 'product_name', 'order' => $to_order ) ) ); ?>"><?php esc_html_e( 'Domain', 'yith-woocommerce-affiliates' ); ?></a>
                </th>
                <th class="column-rate">
                    <a rel="nofollow" class="<?php echo ( 'rate' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?>" href="<?php echo esc_url( add_query_arg( array( 'orderby' => 'rate', 'order' => $to_order ) ) ); ?>"><?php esc_html_e( 'Coupon', 'yith-woocommerce-affiliates' ); ?></a>
                </th>
                <th class="column-amount">
                    <a rel="nofollow" class="<?php echo ( 'amount' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?>" href="<?php echo esc_url( add_query_arg( array( 'orderby' => 'amount', 'order' => $to_order ) ) ); ?>"><?php esc_html_e( 'Bonus', 'yith-woocommerce-affiliates' ); ?></a>
                </th>
                <th class="column-status">
                    <a rel="nofollow" class="<?php echo ( 'status' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?>" href="<?php echo esc_url( add_query_arg( array( 'orderby' => 'status', 'order' => $to_order ) ) ); ?>"><?php esc_html_e( 'Status', 'yith-woocommerce-affiliates' ); ?></a>
                </th>
            </tr>
            </thead>
            <tbody>
                <?php if ( ! empty( $commissions ) ) : ?>
                    <?php foreach ( $commissions as $commission ) : ?>
                        <tr>
                            <td class="column-id"><?php echo esc_html( $commission['ID'] ); ?> <span><?php echo esc_html( $commission['order_id'] ); ?></span></td>
                            <td class="column-date"><?php echo esc_html( date_i18n( wc_date_format(), strtotime( $commission['created_at'] ) ) ); ?></td>
                            <td class="column-product"><a target="_blank" href="<?php echo esc_url( get_permalink( $commission['product_id'] ) ); ?>"><?php echo do_shortcode( '[xyz-ips snippet="order"]' ); ?></a>
</td>
                            <td class="column-rate"><?php foreach ( $coupons as $coupon_id => $coupon ) : ?><?php echo esc_html( $coupon['amount'] ); ?> <?php endforeach; ?></td>
                            <td class="column-amount"><?php echo wc_price( $commission['amount'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
                            <td class="column-status <?php echo esc_attr( $commission['status'] ); ?>"><a rel="nofollow" href="<?php echo esc_url( add_query_arg( 'status', $commission['status'] ) ); ?>"><?php echo esc_html( YITH_WCAF_Commission_Handler()->get_readable_status( $commission['status'] ) ); ?></a></td>
                        </tr>
                    <?php endforeach; ?>
                <?php else : ?>
                    <tr>
                        <td class="empty-set" colspan="6"><?php esc_html_e( 'Sorry! There are no registered commissions yet', 'yith-woocommerce-affiliates' ); ?></td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>

在此代码行中:

<td class="column-product"><a target="_blank" href="<?php echo esc_url( get_permalink( $commission['product_id'] ) ); ?>"><?php echo do_shortcode( '[xyz-ips snippet="order"]' ); ?></a></td>

我已经粘贴了 php 代码的简码。

这是短代码中的代码:

<?php 
global $wpdb;
// the object WC_Order
$order =  wc_get_order(2314 );

$data = $order->get_data(); // order data
echo $data['billing']['company'];

?>

代码成功运行并输出“company”字段。但是有一个问题。我需要 wc_get_order( 2314 ); 行插入一个函数来替换页面中的订单 ID。

订单ID通过代码显示在页面上:

<td class="column-id"><?php echo esc_html( $commission['ID'] ); ?> <span><?php echo esc_html( $commission['order_id'] ); ?></span></td>

如何输入“wc_get_order(2314);”而不是代码中的“2314” ID

表格如下所示:

P粉969253139
P粉969253139

全部回复(1)
P粉563446579

后端添加自定义参数orderid

<?php echo do_shortcode( '[xyz-ips snippet="order" orderid="'. $commission['order_id'] . '"]' ); ?>

您的短代码脚本:

<?php 
global $wpdb;
// the object WC_Order
$order =  wc_get_order({orderid});

$data = $order->get_data(); // order data
echo $data['billing']['company'];

?>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号