我正在 Build 一个基于wooCommerce Platform for WordPress的电子商务商店 . 如果我访问http://mysiteurl/shop这样的商店页面,那么它会显示可用的产品列表 .

我的要求是为赞助商提供另类商店网址,例如http://mysiteurl/shop/sponsor/sponsorname . 我需要这个链接来跟踪由哪个赞助商赞助的订单,以便我可以向我的赞助商提供适当的佣金 .

我对php / wordpress / woocommerce没有太多的了解,但经过一些研发后,我可以根据URL重写的要求为商店创建替代URL . 对于URL重写,我在主题文件夹下的functions.php中完成了以下代码 .

add_action('init', 'custom_shop_sponsor');

function custom_shop_sponsor() {
add_rewrite_tag('%sponsor%','([^&]+)');
add_rewrite_rule('^shop/sponsor/([^/]+)/?$','index.php?
pagename=shop&sponsor=$matches[1]','top');
}

完成上述代码后,我可以访问具有所需URL的商店页面,如http://mysiteurl/shop/sponsor/sponsorname,但在此页面上没有产品列表 . 它只显示文字"Showing The Single Result"

enter image description here

为什么产品不会来?如果我的要求存在任何其他解决方案,请另外建议 .