【问题标题】:Woocommerce custom product variableWoocommerce 自定义产品变量
【发布时间】:2017-10-03 21:13:48
【问题描述】:

所以我对 Wordpress 和 Woocommerce 产品有一个问题,在循环中的单个产品页面上,我创建了如下自定义变量:

// Quantity
$quantity = get_post_meta( $post->ID, "wccaf_quantity", true ); 
// Regular Price
$regular_price = get_post_meta( get_the_ID(), '_regular_price', true);
// Subtotal
$subtotal = $quantity * $regular_price;

计算基于用户通过 Wordpress 管理面板输入的自定义字段。这一切都在前端工作,但我遇到了一个问题,我想在产品页面上对产品进行排序,例如。 $小计变量。有没有可能我可以以某种方式实现这一点,将这个变量称为 post meta 之类的。我对 PHP 没问题,但不知道这在 Wordpress 中是如何工作的

您可以在此处查看网站,投资详情中的描述选项卡: http://aldinmujkic.website/yehuda1/product/amazonbasics-apple-certified-lightning-to-usb-cable/

【问题讨论】:

  • 您想根据小计对 wp-admin 中的产品进行排序吗?我理解正确吗?
  • @berend 不,在前端,在产品页面上。我只是说明 $subtotal 的示例,还有更多其他变量。

标签: php wordpress variables woocommerce


【解决方案1】:

是的,您可以使用帖子元查询帖子。下面的例子

<?php
    $posts_args = array(
        'post_type'         => 'products',
        'posts_per_page'    => 7,
        'meta_key'          => 'smount_post_views', //name your post meta
        'orderby'           => 'meta_value_num',
        'order'             => 'DESC'
    );

    $posts_query = new WP_Query( $posts_args );

    if( $posts_query->have_posts() ):
        while( $posts_query->have_posts() ): $posts_query->the_post();
            get_template_part( 'template-parts/content', get_post_format() );
        endwhile; 
    endif;
 ?>

【讨论】:

    猜你喜欢
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 2019-06-26
    • 1970-01-01
    相关资源
    最近更新 更多