gpt4 book ai didi

php - 向在新窗口中打开的 Woocommerce 我的帐户订单添加操作按钮

转载 作者:行者123 更新时间:2023-12-01 04:35:50 26 4
gpt4 key购买 nike

我将从我的帐户订单中添加一个按钮,使其转到特定的网址。我制作了一个按钮,但我想用新窗口打开它而不是转到页面。我应该怎么办?下面是我添加的代码,我想用笼子打开这里的网址:

function sv_add_my_account_order_actions( $actions, $order ) {

$actions['name'] = array(
'url' => 'the_action_url',
'name' => 'The Button Text',
);
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'sv_add_my_account_order_actions', 10, 2 );

如何将 target="_blank" 添加到每个附加自定义按钮?

最佳答案

使用以下命令将属性 target 添加到每个特定操作 html 标记中,并使用 _blank 值在新窗口中打开链接:

// Your additional action button
add_filter( 'woocommerce_my_account_my_orders_actions', 'add_my_account_my_orders_custom_action', 10, 2 );
function add_my_account_my_orders_custom_action( $actions, $order ) {
$action_slug = 'specific_name';

$actions[$action_slug] = array(
'url' => home_url('/the_action_url/'),
'name' => 'The Button Text',
);
return $actions;
}

// Jquery script
add_action( 'woocommerce_after_account_orders', 'action_after_account_orders_js');
function action_after_account_orders_js() {
$action_slug = 'specific_name';
?>
<script>
jQuery(function($){
$('a.<?php echo $action_slug; ?>').each( function(){
$(this).attr('target','_blank');
})
});
</script>
<?php
}

代码位于事件子主题(或事件主题)的functions.php 文件中。经过测试并有效。

You will have to set the same unique and explicit $action_slug variable in both functions.

<小时/>

要仅定位订单完成,请仅在第一个函数中添加 if ( $order->has_status('completed') ) {,例如:

add_filter( 'woocommerce_my_account_my_orders_actions', 'add_my_account_my_orders_custom_action', 10, 2 );
function add_my_account_my_orders_custom_action( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
$action_slug = 'specific_name';

$actions[$action_slug] = array(
'url' => home_url('/the_action_url/'),
'name' => 'The Button Text',
);
}
return $actions;
}

关于php - 向在新窗口中打开的 Woocommerce 我的帐户订单添加操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56143513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com