php - 我需要更改代码以应用它所在的位置
问题描述
我有在订单列表之后添加一个带有操作的按钮的代码。
我希望将相同的代码作为简码插入,正是我插入它的位置。
该按钮仅在订单状态为 ywraq-pending 时出现。当我单击批准预算按钮时,它会更改订单状态。
//
//Botão Aprovar Orçamento Cliente
//
//
function customer_order_confirm_args( $order_id ) {
return array(
'url' => wp_nonce_url( add_query_arg( 'complete_order', $order_id ) , 'wc_complete_order' ),
'name' => __( 'Aprovar Orçamento', 'woocommerce' )
);
}
// Add a custom action button to processing orders (My account > Orders)
add_filter( 'woocommerce_my_account_my_orders_actions', 'complete_action_button_my_accout_orders', 50, 2 );
function complete_action_button_my_accout_orders( $actions, $order ) {
if ( $order->has_status( 'ywraq-pending' ) ) {
$actions['order_confirmed'] = customer_order_confirm_args( $order->get_id() );
}
return $actions;
}
// Add a custom button to processing orders (My account > View order)
add_action( 'woocommerce_order_details_after_order_table', 'complete_action_button_my_accout_order_view' );
function complete_action_button_my_accout_order_view( $order ){
// Avoiding displaying buttons on email notification && only for orders with ywraq-pending status
if( is_wc_endpoint_url( 'view-quote' )
&& $order->has_status( 'ywraq-pending' ) ) {
$data = customer_order_confirm_args( $order->get_id() );
echo '<div style="margin:-16px 0 14px; position: absolute; top: 10px; left: 3px; width: 240px; height: 150px "><a class="button" href="'.$data['url'].'">'.$data['name'].'</a></div>';
}
}
// Change order status and display a message
add_action( 'template_redirect', 'action_complete_order_status' );
function action_complete_order_status( $query ) {
if ( ( is_wc_endpoint_url( 'orders' )
|| is_wc_endpoint_url( 'view-quote' ) )
&& isset( $_GET['complete_order'] )
&& $_GET['complete_order'] > 1
&& isset($_GET['_wpnonce'])
&& wp_verify_nonce($_GET['_wpnonce'], 'wc_complete_order') )
{
$order = wc_get_order( absint($_GET['complete_order']) );
if ( is_a($order, 'WC_Order') ) {
// Change order status to "ywraq-accepted"
$order->update_status( 'ywraq-accepted', __('Approvado pelo cliente', 'woocommerce') ) ;
// Add a notice (optional)
wc_add_notice( sprintf( __( 'Pedido #%s foi aprovado', 'woocommerce' ), $order->get_id() ) );
// Remove query args
wp_redirect( esc_url( remove_query_arg( array( 'complete_order', '_wpnonce' ) ) ) );
exit();
}
}
}
algeum 能帮我做出这个改变吗?
解决方案
推荐阅读
- react-native - 使用 VS Appcenter 构建 React Native App - p12 密码错误?
- reactjs - 我想制作一个呈现所有数据的 FlatList
- c# - 如何为返回十进制的 IActionResult 控制器操作创建单元测试?
- r - 使用 POSIXct 类更改 R 中的日期时间格式
- node.js - 使用 kafkajs 的 RequestReply 模式
- javascript - HTML 和 Javascript:打开文件资源管理器以允许用户选择目录而不仅仅是文件,没有 webkitdirectory 属性?
- java - 如何修复“字段列表”错误 Glassfish 服务器中的未知列
- python - 我在为我的 fps 游戏编写碰撞检查功能时遇到问题。如何编写我的碰撞函数?
- java - 解析为 LocalTime 模式 mm:ss.S
- regex - 缺少空格的正则表达式单独的行