我已经创建了一个插件。插件替换了add to cart按钮,以继续botton.for弹出店主选择的每个产品。我希望在单击按钮时将用户重定向到我的自定义页面。我需要该页面将显示不同的产品标识的不同的东西。我应该把网页放在我的插件文件夹中吗?
我怎么重定向到它呢?
我需要该页面将使用商店主题,例如,通过在url…中获取产品id,该页面将按原样显示产品页。
代码是将按钮替换为id的函数。
function replacing_add_to_cart_button( $button, $product ) {
$product_id = $product->get_id();
//
global $wpdb;
$shopName = getShopName();
$existQuary = "SELECT * FROM `wp_onePlusOne` WHERE `id` = '$product_id'";
$existQuaryRes = $wpdb->get_results($existQuary);//simplafy query
if(!empty($existQuaryRes)){
$id_onePlusOne = get_object_vars($existQuaryRes[0])['id'];
$button_text = __("1+1", "woocommerce");
$button ="".$button."
1+1
×
" . $button_text . '' ."
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}
.modal-content".$id_onePlusOne." {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close".$id_onePlusOne." {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close".$id_onePlusOne.":hover,
.close".$id_onePlusOne.":focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
function display".$id_onePlusOne."() {
document.getElementById('myModal".$id_onePlusOne."').style.display = 'block';
}
function unDisplay".$id_onePlusOne."() {
document.getElementById('myModal".$id_onePlusOne."').style.display = 'none';
}
function spanDisplay".$id_onePlusOne."() {
document.getElementById('myModal".$id_onePlusOne."').style.display = 'none';
}
window.onclick = function(event) {
if (event.target == document.getElementById('myModal".$id_onePlusOne."')) {
document.getElementById('myModal".$id_onePlusOne."').style.display = 'none';
}
}
" ;
}
return $button;
}谢谢!
发布于 2018-05-10 11:21:19
您可以使用template_include筛选器来更改重定向链接的通常模板。您还可以将其与template_redirect操作混合使用。https://codex.wordpress.org/Plugin_API/过滤器_参考/模板_包括
https://wordpress.stackexchange.com/questions/303205
复制相似问题