ID, '_loyaltypress_coins_mode', true ); $plural = (string) Settings::get( 'coins.plural' ); echo '
'; woocommerce_wp_select( array( 'id' => '_loyaltypress_coins_mode', /* translators: %s: coin name, e.g. "Star Coins" */ 'label' => sprintf( __( 'Loyalty %s', 'loyaltyspin' ), $plural ), 'options' => array( 'default' => __( 'Store earn rate (default)', 'loyaltyspin' ), 'fixed' => __( 'Fixed amount per unit', 'loyaltyspin' ), 'none' => __( 'No coins for this product', 'loyaltyspin' ), ), 'value' => $mode ? $mode : 'default', 'desc_tip' => true, 'description' => __( 'Default uses the earn rate in LoyaltySpin → Settings → Coins. "Fixed" gives the same coins per unit whatever the price (great for promotions). "No coins" excludes the product, e.g. gift cards.', 'loyaltyspin' ), ) ); woocommerce_wp_text_input( array( 'id' => '_loyaltypress_coins_fixed', /* translators: %s: coin name */ 'label' => sprintf( __( '%s per unit', 'loyaltyspin' ), $plural ), 'type' => 'number', 'custom_attributes' => array( 'min' => '0', 'step' => '1', ), 'value' => get_post_meta( $post->ID, '_loyaltypress_coins_fixed', true ), 'desc_tip' => true, 'description' => __( 'Used only when "Fixed amount per unit" is selected.', 'loyaltyspin' ), ) ); echo '
'; wc_enqueue_js( "jQuery( '#_loyaltypress_coins_mode' ).on( 'change', function () { jQuery( '._loyaltypress_coins_fixed_field' ).toggle( 'fixed' === this.value ); } ).trigger( 'change' );" ); } /** * Save fields (WooCommerce's product nonce and the edit capability are checked again here). * * @param \WC_Product $product Product. */ public static function save( $product ) { $nonce = isset( $_POST['woocommerce_meta_nonce'] ) ? sanitize_key( wp_unslash( $_POST['woocommerce_meta_nonce'] ) ) : ''; if ( ! wp_verify_nonce( $nonce, 'woocommerce_save_data' ) || ! current_user_can( 'edit_post', $product->get_id() ) ) { return; } $mode = isset( $_POST['_loyaltypress_coins_mode'] ) ? sanitize_key( wp_unslash( $_POST['_loyaltypress_coins_mode'] ) ) : 'default'; $qty = isset( $_POST['_loyaltypress_coins_fixed'] ) ? absint( wp_unslash( $_POST['_loyaltypress_coins_fixed'] ) ) : 0; $product->update_meta_data( '_loyaltypress_coins_mode', in_array( $mode, array( 'fixed', 'none' ), true ) ? $mode : 'default' ); $product->update_meta_data( '_loyaltypress_coins_fixed', $qty ); } }