Luc*_*pan 0 php wordpress woocommerce
设置
我有一个带有 Elementor 的 WooCommerce 商店。
我正在使用 Elementor 单一产品页面模板来生成每个产品的产品页面。
我想使用这个插件在每个产品页面上显示经常一起购买 (FBT) 元素。
为了显示 FBT 元素,插件的创建者提供了以下短代码:[premmerce_get_bundles_by_main_product_id id="X"],其中X是 WooCommerce 产品 ID。
问题
这X动态的。
如果我在短代码中填写例如产品的产品 ID ,Elementor 产品页面模板将显示我的每个产品2的 FBT 产品。2
问题
可以做X动态吗?优选地,X自动将其设置为正在访问哪个页面的产品的id。
小智 5
您可以尝试扩展简码:
function so_extend_frequent_bought_shortcode() {
global $product;
$id = $product->get_id();
return do_shortcode( '[premmerce_get_bundles_by_main_product_id id="' . $id . '"]');
}
add_shortcode( 'my_new_shortcode', 'so_extend_frequent_bought_shortcode' );
Run Code Online (Sandbox Code Playgroud)
现在您只需输入[my_new_shortcode]您的帖子即可。如果您无法编辑functions.php,请使用名为Code Snippets的插件