I'm using Wordpress with Woocommerce and using Affiliates Woocommerce Light
This plugin has a limitation: you can setup only a fixed comission for all products.
I need different comissions for each product.
I thought creating a custom field for product in product page when inserting a product.
Then I will access to that comission and calculate the commission to pay.
In affiliates-woocommerce-light.php I have:
public static function woocommerce_checkout_order_processed( $order_id ) {
$order_total = get_post_meta( $order_id, '_order_total', true );
$order_tax = get_post_meta( $order_id, '_order_tax', true );
$order_shipping = get_post_meta( $order_id, '_order_shipping', true );
$order_shipping_tax = get_post_meta( $order_id, '_order_shipping_tax', true );
$order_subtotal = $order_total - $order_tax - $order_shipping - $order_shipping_tax;
$currency = get_option( 'woocommerce_currency' );
$order_link = '<a href="' . admin_url( 'post.php?post=' . $order_id . '&action=edit' ) . '">';
$order_link .= sprintf( __( 'Order #%s', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ), $order_id );
$order_link .= "</a>";
$data = array(
'order_id' => array(
'title' => 'Order #',
'domain' => AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN,
'value' => esc_sql( $order_id )
),
'order_total' => array(
'title' => 'Total',
'domain' => AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN,
'value' => esc_sql( $order_subtotal )
),
'order_currency' => array(
'title' => 'Currency',
'domain' => AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN,
'value' => esc_sql( $currency )
),
'order_link' => array(
'title' => 'Order',
'domain' => AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN,
'value' => esc_sql( $order_link )
),
'order_link' => array(
'title' => 'comissao',
'domain' => AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN,
'value' => esc_sql( $order_link )
)
);
$options = get_option( self::PLUGIN_OPTIONS , array() );
$referral_rate = isset( $options[self::REFERRAL_RATE] ) ? $options[self::REFERRAL_RATE] : self::REFERRAL_RATE_DEFAULT;
$amount = round( floatval( $referral_rate ) * floatval( $price ), AFFILIATES_REFERRAL_AMOUNT_DECIMALS );
$description = sprintf( 'Order #%s', $order_id );
affiliates_suggest_referral( $order_id, $description, $data, $amount, $currency );
}
So, I will need a to add a function like
public static function woocommerce_get_comission( $product_id ) {
$comission = get_post_meta($product_id, '_comission', true );
}
and then modify
$amount = round( floatval( $referral_rate ) * floatval( $order_subtotal ), AFFILIATES_REFERRAL_AMOUNT_DECIMALS );
to
$amount = round( floatval( $comission ), AFFILIATES_REFERRAL_AMOUNT_DECIMALS );
but no success until now....
any ideas??
cheers