将页面中的订单 ID 插入 wc_get_order() 函数
P粉969253139
P粉969253139 2023-09-02 14:10:45
[PHP讨论组]
<p>我想将数据输出更改为表格。</p> <p>这是表格代码:</p> <pre class="brush:php;toolbar:false;">&lt;div class=&quot;filters&quot;&gt; &lt;form&gt; &lt;div class=&quot;filters-row&quot;&gt; &lt;input type=&quot;hidden&quot; class=&quot;product-search wc-product-search&quot; name=&quot;product_id&quot; data-placeholder=&quot;&lt;?php esc_html_e( 'Product:', 'yith-woocommerce-affiliates' ); ?&gt;&quot; value=&quot;&lt;?php echo esc_attr( $product_id ); ?&gt;&quot; data-selected=&quot;&lt;?php echo esc_attr( $product_name ); ?&gt;&quot; /&gt; &lt;input type=&quot;text&quot; class=&quot;datepicker&quot; name=&quot;from&quot; placeholder=&quot;&lt;?php esc_html_e( 'From:', 'yith-woocommerce-affiliates' ); ?&gt;&quot; value=&quot;&lt;?php echo esc_attr( $from ); ?&gt;&quot;/&gt; &lt;input type=&quot;text&quot; class=&quot;datepicker&quot; name=&quot;to&quot; placeholder=&quot;&lt;?php esc_html_e( 'To:', 'yith-woocommerce-affiliates' ); ?&gt;&quot; value=&quot;&lt;?php echo esc_attr( $to ); ?&gt;&quot;/&gt; &lt;label for=&quot;per_page&quot; class=&quot;per-page&quot;&gt; &lt;?php esc_html_e( 'Items per page:', 'yith-woocommerce-affiliates' ); ?&gt; &lt;input max=&quot;100&quot; min=&quot;1&quot; step=&quot;1&quot; type=&quot;number&quot; name=&quot;per_page&quot; value=&quot;&lt;?php echo esc_attr( $per_page ); ?&gt;&quot;/&gt; &lt;/label&gt; &lt;/div&gt; &lt;div class=&quot;button-row&quot;&gt; &lt;input type=&quot;submit&quot; value=&quot;&lt;?php esc_html_e( 'Filter', 'yith-woocommerce-affiliates' ); ?&gt;&quot;/&gt; &lt;?php if ( $filter_set ) : ?&gt; &lt;a href=&quot;&lt;?php echo esc_url( $dashboard_commissions_link ); ?&gt;&quot;&gt;&lt;?php esc_html_e( 'Reset', 'yith-woocommerce-affiliates' ); ?&gt;&lt;/a&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;table class=&quot;shop_table&quot; id=&quot;table&quot;&gt; &lt;thead&gt; &lt;tr&gt; &lt;th class=&quot;column-id&quot;&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;&lt;?php echo ( 'ID' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?&gt;&quot; href=&quot;&lt;?php echo esc_url( add_query_arg( array( 'orderby' =&gt; 'ID', 'order' =&gt; $to_order ) ) ); ?&gt;&quot;&gt;&lt;?php esc_html_e( '#/ID', 'yith-woocommerce-affiliates' ); ?&gt;&lt;/a&gt; &lt;/th&gt; &lt;th class=&quot;column-date&quot;&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;&lt;?php echo ( 'created_at' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?&gt;&quot; href=&quot;&lt;?php echo esc_url( add_query_arg( array( 'orderby' =&gt; 'created_at', 'order' =&gt; $to_order ) ) ); ?&gt;&quot;&gt;&lt;?php esc_html_e( 'Date', 'yith-woocommerce-affiliates' ); ?&gt;&lt;/a&gt; &lt;/th&gt; &lt;th class=&quot;column-product&quot;&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;&lt;?php echo ( 'product_name' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?&gt;&quot; href=&quot;&lt;?php echo esc_url( add_query_arg( array( 'orderby' =&gt; 'product_name', 'order' =&gt; $to_order ) ) ); ?&gt;&quot;&gt;&lt;?php esc_html_e( 'Domain', 'yith-woocommerce-affiliates' ); ?&gt;&lt;/a&gt; &lt;/th&gt; &lt;th class=&quot;column-rate&quot;&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;&lt;?php echo ( 'rate' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?&gt;&quot; href=&quot;&lt;?php echo esc_url( add_query_arg( array( 'orderby' =&gt; 'rate', 'order' =&gt; $to_order ) ) ); ?&gt;&quot;&gt;&lt;?php esc_html_e( 'Coupon', 'yith-woocommerce-affiliates' ); ?&gt;&lt;/a&gt; &lt;/th&gt; &lt;th class=&quot;column-amount&quot;&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;&lt;?php echo ( 'amount' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?&gt;&quot; href=&quot;&lt;?php echo esc_url( add_query_arg( array( 'orderby' =&gt; 'amount', 'order' =&gt; $to_order ) ) ); ?&gt;&quot;&gt;&lt;?php esc_html_e( 'Bonus', 'yith-woocommerce-affiliates' ); ?&gt;&lt;/a&gt; &lt;/th&gt; &lt;th class=&quot;column-status&quot;&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;&lt;?php echo ( 'status' === $ordered ) ? 'ordered to-order-' . esc_attr( strtolower( $to_order ) ) : ''; ?&gt;&quot; href=&quot;&lt;?php echo esc_url( add_query_arg( array( 'orderby' =&gt; 'status', 'order' =&gt; $to_order ) ) ); ?&gt;&quot;&gt;&lt;?php esc_html_e( 'Status', 'yith-woocommerce-affiliates' ); ?&gt;&lt;/a&gt; &lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php if ( ! empty( $commissions ) ) : ?&gt; &lt;?php foreach ( $commissions as $commission ) : ?&gt; &lt;tr&gt; &lt;td class=&quot;column-id&quot;&gt;&lt;?php echo esc_html( $commission['ID'] ); ?&gt; &lt;span&gt;&lt;?php echo esc_html( $commission['order_id'] ); ?&gt;&lt;/span&gt;&lt;/td&gt; &lt;td class=&quot;column-date&quot;&gt;&lt;?php echo esc_html( date_i18n( wc_date_format(), strtotime( $commission['created_at'] ) ) ); ?&gt;&lt;/td&gt; &lt;td class=&quot;column-product&quot;&gt;&lt;a target=&quot;_blank&quot; href=&quot;&lt;?php echo esc_url( get_permalink( $commission['product_id'] ) ); ?&gt;&quot;&gt;&lt;?php echo do_shortcode( '[xyz-ips snippet=&quot;order&quot;]' ); ?&gt;&lt;/a&gt; &lt;/td&gt; &lt;td class=&quot;column-rate&quot;&gt;&lt;?php foreach ( $coupons as $coupon_id =&gt; $coupon ) : ?&gt;&lt;?php echo esc_html( $coupon['amount'] ); ?&gt; &lt;?php endforeach; ?&gt;&lt;/td&gt; &lt;td class=&quot;column-amount&quot;&gt;&lt;?php echo wc_price( $commission['amount'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?&gt;&lt;/td&gt; &lt;td class=&quot;column-status &lt;?php echo esc_attr( $commission['status'] ); ?&gt;&quot;&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;&lt;?php echo esc_url( add_query_arg( 'status', $commission['status'] ) ); ?&gt;&quot;&gt;&lt;?php echo esc_html( YITH_WCAF_Commission_Handler()-&gt;get_readable_status( $commission['status'] ) ); ?&gt;&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach; ?&gt; &lt;?php else : ?&gt; &lt;tr&gt; &lt;td class=&quot;empty-set&quot; colspan=&quot;6&quot;&gt;&lt;?php esc_html_e( 'Sorry! There are no registered commissions yet', 'yith-woocommerce-affiliates' ); ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endif; ?&gt; &lt;/tbody&gt; &lt;/table&gt;</pre> <p>在此代码行中:</p> <pre class="brush:php;toolbar:false;">&lt;td class=&quot;column-product&quot;&gt;&lt;a target=&quot;_blank&quot; href=&quot;&lt;?php echo esc_url( get_permalink( $commission['product_id'] ) ); ?&gt;&quot;&gt;&lt;?php echo do_shortcode( '[xyz-ips snippet=&quot;order&quot;]' ); ?&gt;&lt;/a&gt;&lt;/td&gt;</pre> <p>我已经粘贴了 php 代码的简码。</p> <p>这是短代码中的代码:</p> <pre class="brush:php;toolbar:false;">&lt;?php global $wpdb; // the object WC_Order $order = wc_get_order(2314 ); $data = $order-&gt;get_data(); // order data echo $data['billing']['company']; ?&gt;</pre> <p>代码成功运行并输出“company”字段。但是有一个问题。我需要 wc_get_order( 2314 ); 行插入一个函数来替换页面中的订单 ID。</p> <p>订单ID通过代码显示在页面上:</p> <pre class="brush:php;toolbar:false;">&lt;td class=&quot;column-id&quot;&gt;&lt;?php echo esc_html( $commission['ID'] ); ?&gt; &lt;span&gt;&lt;?php echo esc_html( $commission['order_id'] ); ?&gt;&lt;/span&gt;&lt;/td&gt;</pre> <p>如何输入“wc_get_order(2314);”而不是代码中的“2314” ID <code><?php echo esc_html( $commission['order_id'] ); ?></code></p> <p>表格如下所示: </p>
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'];

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

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