您可以尝试以下操作:
add_action( \'woocommerce_before_add_to_cart_form\', \'add_list_completed_orders\' );
function add_list_completed_orders() {
// get orders
$orders = wc_get_orders (
array (
\'status\' => array( \'wc-completed\' ),
\'type\' => \'shop_order\',
\'limit\' => -1,
\'return\' => \'ids\',
\'customer_id\' => get_current_user_id(),
)
);
if ( ! empty( $orders ) ) {
// set value options
$options = \'\';
foreach ( $orders as $order_id ) {
$options .= \'<option value="\' . $order_id . \'">\' . $order_id . \'</option>\';
}
// add list
$form = \'<label for="orders">Select completed orders:</label>\';
$form .= \'<select id="orders" name="orders">\' . $options . \'</select>\';
echo $form;
}
}
经过测试,效果良好。代码进入主题的函数。php。