【问题标题】:Change product link in woocommerce on content-product.php在 content-product.php 上更改 woocommerce 中的产品链接
【发布时间】:2015-07-23 20:14:54
【问题描述】:

我需要更改显示为 http://localhost/product/happy-ninja/ 的链接 到http://localhost/product/happy-ninja?product=$product_id content-product.php 中的代码如下所示(第 44 行):

<a href="<?php the_permalink($product_id); ?>">

如何添加零件?product= 感谢您的帮助

【问题讨论】:

  • 目的是什么?您可以轻松地告诉 WooCommerce 使用 localhost?product=$product_id 作为永久链接。
  • 你能告诉我具体是怎么做的吗?
  • 您可以在后台edit your site's permalinks。设置>固定链接。但是,我很抱歉,因为我认为 ?product=$product_id 是您可以从永久链接设置中选择的一个选项,因为您可以显示这样的帖子/页面。但是它不是默认选项,可能需要自定义代码。

标签: php wordpress woocommerce


【解决方案1】:

您可以使用post_link 过滤器修改永久链接

我尚未对其进行测试,但此代码可能有效:

function append_query_string( $url, $post, $leavename ) {
    if ( $post->post_type == 'product' ) {
        $url = add_query_arg( 'product', $post->ID, $url );
    }
    return $url;
}
add_filter( 'post_link', 'append_query_string', 10, 3 );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多