在wordpress中为用户加载编辑屏幕时正在运行代码



我用下面的代码向编辑用户屏幕添加一个额外的按钮,以便在按钮单击时运行函数。然而,它也运行函数EnglishYellowAdd();加载编辑用户屏幕时,而不是只点击一个按钮。有办法解决这个问题吗?按钮工作得很好,它只是在开始时额外的迭代。

add_action('edit_user_profile','EnglishYellow');
function EnglishYellow(){
?>
<button onclick="clickMe()">Lean Six Sigma Yellow Belt </button>
?><script>
function clickMe(){
var call = <?php EnglishYellowAdd();?>

}
</script>
<?php
}
function EnglishYellowAdd() {
global $woocommerce;
$user_id = $_GET['user_id'];
// Now we create the order
$order = wc_create_order();

// The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
$order->add_product( get_product('3356'), 1); // This is an existing SIMPLE product
$order -> set_customer_id($user_id);
//
$order->update_status("Completed", 'Imported order', TRUE);  
}

相关内容

最新更新