php 按商店和类别限制POS产品

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 按商店和类别限制POS产品相关的知识,希望对你有一定的参考价值。

<?php 

// this goes in your functions.php file

function my_custom_pre_get_posts( $query ) {
  
  // early exit if user is not in the POS
  if( ! is_pos() ) {
    return;
  }
  
  // a hard coded map of Store IDs => array of product categories
  $restrict = array(
    1524 => '52,863',        // ie: Store ID 1524 restricted to category ids 52 and 863
    6252 => '-64,-863'       // ie: Store ID 6252 excludes category ids 64 and 863
  );
  
  // get current logged in POS store
  $store_id = get_user_option( 'woocommerce_pos_store' );
  
  // if store is in restrict array, limit the products to mapped categories
  if( ! isset( $restrict[$store_id] ) ) {
    $query->set( 'cat', $restrict[$store_id] );
  }
  
}

add_action( 'pre_get_posts', 'my_custom_pre_get_posts' );

以上是关于php 按商店和类别限制POS产品的主要内容,如果未能解决你的问题,请参考以下文章