AffiliateWP + WooCommerce - 需要从ID

时间:2018-05-20 21:37:12

标签: php wordpress woocommerce

所以,这个人已经进入了一个循环。我已经联系了插件的支持,他们基本上告诉我我是SOL,但我拒绝相信没有办法做到这一点。

我正在使用AffiliateWP将销售归因于一个位置。每个会员都是从Wordpress用户那里获取的,为了他们的昵称,我使用了他们的地址/位置。 不幸的是,插件不包括在订单详细信息屏幕或订单电子邮件中,这是一个很大的问题。我已将frankensteined一些代码放在一起,但不断得到各种未定义的错误,因为他们在课堂上做了所有事情,我想确保像我这样的人不能在那里摆弄?

为会员分配会员的功能:https://github.com/AffiliateWP/AffiliateWP/blob/master/includes/integrations/class-woocommerce.php#L78

检索关联企业用户ID的功能:https://github.com/AffiliateWP/AffiliateWP/blob/master/includes/affiliate-functions.php#L204

检索关联企业名称的功能:https://github.com/AffiliateWP/AffiliateWP/blob/master/includes/affiliate-functions.php#L132

[编辑]最后,我的科学怪人:

 add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
global $Affiliate_WP_WooCommerce;
echo '<p><strong>'.__('My Field').':</strong> ' . affiliate_wp()->affiliates->get_affiliate_name( $affiliate_id ) . '</p>';
}

这不会给我一个错误,但它确实给我一个空白区域......

2 个答案:

答案 0 :(得分:0)

affwp_get_affiliate_name方法在三个条件下返回空白:

if ( ! $affiliate = affwp_get_affiliate( $affiliate ) ) {
    return '';
}
if ( ! $user_info = get_userdata( $affiliate->user_id ) ) {
    return '';
}

...

// If neither are set, return an empty string.
if ( empty( $first_name ) && empty( $last_name ) ) {
    return '';
}

首先手动传递您知道与包含$ first_name和/或$ last_name的记录关联的联属会员ID,例如:

echo '<p><strong>'.__('My Field').':</strong> ' . affiliate_wp()->affiliates->get_affiliate_name(5) . '</p>';

这将排除问题是否与您当前正在传递的$ affiliate_id有关。如果你得到了返回的值,那么修复它应该是一件简单的事情。

在尝试之后,我将尝试更改add_action()的优先级,将其提升到999或者因为它可能在插件中的相关挂钩之前执行。

答案 1 :(得分:0)

尝试一下:

add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
global $Affiliate_WP_WooCommerce;
$order_id       = $order->get_id();
$referrals      = affiliate_wp()->referrals->get_by( 'reference', $order_id);
$affiliate_id   = $referrals->affiliate_id;
echo '<p><strong>'.__('My Field').':</strong> ' . affiliate_wp()->affiliates->get_affiliate_name( $affiliate_id ) . '</p>';
}