根据用户=产品作者启用woocommerce付款网关

时间:2018-08-03 11:41:34

标签: php wordpress woocommerce

我正在基于当前用户是否为产品作者来启用支付网关“ cod”。基本上,在购买自己的产品时,用户应具有额外的现金付款方式,但显然仅适用于自己的产品。我们使用Dokan创建供应商站点。

到目前为止,我的代码:



RewardedVideoAdListener rewardAdListener = new RewardedVideoAdListener() {

    @Override
    public void onRewardedVideoAdLoaded() {
        Toast.makeText(getActivity(),"ad is loaded",Toast.LENGTH_SHORT).show();
        Log.d("ADS_SHOW","loaded");


    }

    @Override
    public void onRewardedVideoAdOpened() {

    }

    @Override
    public void onRewardedVideoStarted() {

    }

    @Override
    public void onRewardedVideoAdClosed() {
        loadRewardedAdVideo();
    }

    @Override
    public void onRewarded(RewardItem rewardItem) {
        int rewardPoints =   rewardItem.getAmount();
        int userPoints = getActivity().getSharedPreferences(PREFERENCE,0).getInt(POINTS,0) - rewardPoints;
        userRef.child(POINTS).setValue(userPoints);
        getActivity().getSharedPreferences(PREFERENCE,0).edit().putInt(POINTS,userPoints).commit();




    }

    @Override
    public void onRewardedVideoAdLeftApplication() {

    }

    @Override
    public void onRewardedVideoAdFailedToLoad(int i) {
        Toast.makeText(getActivity(),"No ads to show "+i,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoCompleted() {





    }
};


private void loadRewardedAdVideo(){
    if(! mRewardedVideoAd.isLoaded()){
         mRewardedVideoAd.loadAd("ca-app-pub-xxxxxxxxx", new AdRequest.Builder().build());
    }
}

有人知道我要去哪里吗?

1 个答案:

答案 0 :(得分:0)

您的函数中几乎没有PHP语法错误。试试这个吧。

add_filter('woocommerce_available_payment_gateways', 'filter_gateways', 1);
function filter_gateways($gateways)
{
   global $woocommerce;
   $current_user = wp_get_current_user();
   $users_product = false;
   foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ){
       $post_obj    = get_post( $cart_item['product_id'] );
       $post_author = $post_obj->post_author;
       if ( is_user_logged_in() && $current_user->ID == $post_author ) $users_product = true;
   }
   if ( $users_product != true ) {
       unset($gateways['cod']);
   }
   return $gateways;
}