term_id, '_pisol_aww_has_custom_cashback', true );
$type = get_term_meta( $term->term_id, '_pisol_aww_cashback_type', true );
$amount = get_term_meta( $term->term_id, '_pisol_aww_cashback_amount', true );
$max_amount = get_term_meta( $term->term_id, '_pisol_aww_max_cashback_amount', true );
?>
|
>
|
|
|
|
|
|
|
';
woocommerce_wp_checkbox( array(
'id' => '_pisol_aww_has_custom_cashback',
'label' => __( 'Enable Custom Cashback', 'advanced-wallet-for-woocommerce' ),
'description' => __( 'Enable this to override global cashback settings for this product.', 'advanced-wallet-for-woocommerce' ),
) );
woocommerce_wp_select( array(
'id' => '_pisol_aww_cashback_type',
'label' => __( 'Cashback Type', 'advanced-wallet-for-woocommerce' ),
'options' => array(
'percentage' => __( 'Percentage', 'advanced-wallet-for-woocommerce' ),
'fixed' => __( 'Fixed Amount', 'advanced-wallet-for-woocommerce' ),
),
'description' => __( 'Select the type of cashback.', 'advanced-wallet-for-woocommerce' ),
) );
woocommerce_wp_text_input( array(
'id' => '_pisol_aww_cashback_amount',
'label' => __( 'Cashback Amount', 'advanced-wallet-for-woocommerce' ),
'data_type' => 'price',
'description' => __( 'Enter the cashback amount or percentage.', 'advanced-wallet-for-woocommerce' ),
) );
woocommerce_wp_text_input( array(
'id' => '_pisol_aww_max_cashback_amount',
'label' => __( 'Max Cashback Amount', 'advanced-wallet-for-woocommerce' ),
'data_type' => 'price',
'description' => __( 'Enter the maximum cashback amount allowed for this product (0 for no limit).', 'advanced-wallet-for-woocommerce' ),
) );
echo '';
}
/**
* Save Simple Product Fields
*/
public function save_product_fields( $post_id ) {
$cashback_rule = get_option("pisol_aww_cashback_rule", "cart");
if($cashback_rule !== 'product') return;
$has_custom = isset( $_POST['_pisol_aww_has_custom_cashback'] ) ? 'yes' : 'no';
update_post_meta( $post_id, '_pisol_aww_has_custom_cashback', $has_custom );
if ( isset( $_POST['_pisol_aww_cashback_type'] ) ) {
update_post_meta( $post_id, '_pisol_aww_cashback_type', sanitize_text_field( $_POST['_pisol_aww_cashback_type'] ) );
}
if ( isset( $_POST['_pisol_aww_cashback_amount'] ) ) {
update_post_meta( $post_id, '_pisol_aww_cashback_amount', wc_clean( $_POST['_pisol_aww_cashback_amount'] ) );
}
if ( isset( $_POST['_pisol_aww_max_cashback_amount'] ) ) {
update_post_meta( $post_id, '_pisol_aww_max_cashback_amount', wc_clean( $_POST['_pisol_aww_max_cashback_amount'] ) );
}
}
/**
* Add fields to Variations
*/
public function add_variation_fields( $loop, $variation_data, $variation ) {
$cashback_rule = get_option("pisol_aww_cashback_rule", "cart");
if($cashback_rule !== 'product') return;
echo '';
woocommerce_wp_checkbox( array(
'id' => 'variable_pisol_aww_has_custom_cashback[' . $loop . ']',
'name' => 'variable_pisol_aww_has_custom_cashback[' . $loop . ']',
'value' => get_post_meta( $variation->ID, '_pisol_aww_has_custom_cashback', true ),
'label' => __( 'Enable Custom Cashback', 'advanced-wallet-for-woocommerce' ),
'description' => __( 'Override global/product settings.', 'advanced-wallet-for-woocommerce' ),
'wrapper_class' => 'form-row form-row-full',
) );
woocommerce_wp_select( array(
'id' => 'variable_pisol_aww_cashback_type[' . $loop . ']',
'name' => 'variable_pisol_aww_cashback_type[' . $loop . ']',
'value' => get_post_meta( $variation->ID, '_pisol_aww_cashback_type', true ),
'label' => __( 'Cashback Type', 'advanced-wallet-for-woocommerce' ),
'options' => array(
'percentage' => __( 'Percentage', 'advanced-wallet-for-woocommerce' ),
'fixed' => __( 'Fixed Amount', 'advanced-wallet-for-woocommerce' ),
),
'wrapper_class' => 'form-row form-row-full',
) );
woocommerce_wp_text_input( array(
'id' => 'variable_pisol_aww_cashback_amount[' . $loop . ']',
'name' => 'variable_pisol_aww_cashback_amount[' . $loop . ']',
'value' => get_post_meta( $variation->ID, '_pisol_aww_cashback_amount', true ),
'label' => __( 'Cashback Amount', 'advanced-wallet-for-woocommerce' ),
'data_type' => 'price',
'wrapper_class' => 'form-row form-row-full',
) );
woocommerce_wp_text_input( array(
'id' => 'variable_pisol_aww_max_cashback_amount[' . $loop . ']',
'name' => 'variable_pisol_aww_max_cashback_amount[' . $loop . ']',
'value' => get_post_meta( $variation->ID, '_pisol_aww_max_cashback_amount', true ),
'label' => __( 'Max Cashback Amount', 'advanced-wallet-for-woocommerce' ),
'data_type' => 'price',
'wrapper_class' => 'form-row form-row-full',
) );
echo '
';
}
/**
* Save Variation Fields
*/
public function save_variation_fields( $variation_id, $i ) {
$cashback_rule = get_option("pisol_aww_cashback_rule", "cart");
if($cashback_rule !== 'product') return;
$has_custom = isset( $_POST['variable_pisol_aww_has_custom_cashback'][$i] ) ? 'yes' : 'no';
update_post_meta( $variation_id, '_pisol_aww_has_custom_cashback', $has_custom );
if ( isset( $_POST['variable_pisol_aww_cashback_type'][$i] ) ) {
update_post_meta( $variation_id, '_pisol_aww_cashback_type', sanitize_text_field( $_POST['variable_pisol_aww_cashback_type'][$i] ) );
}
if ( isset( $_POST['variable_pisol_aww_cashback_amount'][$i] ) ) {
update_post_meta( $variation_id, '_pisol_aww_cashback_amount', wc_clean( $_POST['variable_pisol_aww_cashback_amount'][$i] ) );
}
if ( isset( $_POST['variable_pisol_aww_max_cashback_amount'][$i] ) ) {
update_post_meta( $variation_id, '_pisol_aww_max_cashback_amount', wc_clean( $_POST['variable_pisol_aww_max_cashback_amount'][$i] ) );
}
}
}