【问题标题】:Wordpress Woocommerce Orders by AuthorWordpress Woocommerce 作者的订单
【发布时间】:2016-09-28 00:11:28
【问题描述】:

我在一个基于作者的 woocommerce 商店工作。我尝试做的是只显示作者的帖子,客户的订单链接到产品作者。

这是我目前得到的:

function show_author_posts_only($query) {
global $user_level, $woocommerce, $product;

if($query->is_admin && $user_level < 5) {
    global $user_ID;

    $query->set('post_author',  get_post_field( 'post_author', $product_id ));
    $query->set('author',  $user_ID);
    unset($user_ID);
}
unset($user_level);

return $query; 
}
add_filter('pre_get_posts', 'show_author_posts_only');

糟糕的是,我被困在订单部分.. 有人有建议吗?

谢谢。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:
     we need to now add this to our sorting dropdown and our WooCommerce settings.
    
     <?php 
     function sv_custom_woocommerce_catalog_orderby( $sortby ) {
        $sortby['alphabetical'] = 'Sort by sell: alphabetical';
        return $sortby;
    }
    add_filter( 'woocommerce_default_catalog_orderby_options', 'sv_custom_woocommerce_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'sv_custom_woocommerce_catalog_orderby' );
    
    
    //Add Alphabetical sorting option to shop page / WC Product Settings
    function sv_alphabetical_woocommerce_shop_ordering( $sort_args ) {
      $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    
        if ( 'alphabetical' == $orderby_value ) {
            $sort_args['orderby'] = 'author';
            $sort_args['order'] = 'asc';
            $sort_args['meta_key'] = '';
        }
    
        return $sort_args;
    }
    add_filter( 'woocommerce_get_catalog_ordering_args', 'sv_alphabetical_woocommerce_shop_ordering' );
    ?>
    

    【讨论】:

      猜你喜欢
      • 2021-08-09
      • 1970-01-01
      • 2019-07-29
      • 2019-01-27
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      相关资源
      最近更新 更多