| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.9/wp-content/plugins/woocommerce/assets/js/admin/ |
Upload File : |
/* global woocommerce_admin_meta_boxes_coupon */
jQuery(function( $ ) {
/**
* Coupon actions
*/
var wc_meta_boxes_coupon_actions = {
/**
* Initialize variations actions
*/
init: function() {
$( 'select#discount_type' )
.on( 'change', this.type_options )
.trigger( 'change' );
this.insert_generate_coupon_code_button();
$( '.button.generate-coupon-code' ).on( 'click', this.generate_coupon_code );
},
/**
* Show/hide fields by coupon type options
*/
type_options: function() {
// Get value
var select_val = $( this ).val();
if ( 'percent' === select_val ) {
$( '#coupon_amount' ).removeClass( 'wc_input_price' ).addClass( 'wc_input_decimal' );
} else {
$( '#coupon_amount' ).removeClass( 'wc_input_decimal' ).addClass( 'wc_input_price' );
}
if ( select_val !== 'fixed_cart' ) {
$( '.limit_usage_to_x_items_field' ).show();
} else {
$( '.limit_usage_to_x_items_field' ).hide();
}
},
/**
* Insert generate coupon code button HTML.
*/
insert_generate_coupon_code_button: function () {
const $title = $('.post-type-shop_coupon').find('#title');
const button = document.createElement('a');
button.href = '#';
button.className = 'button generate-coupon-code';
button.textContent =
woocommerce_admin_meta_boxes_coupon.generate_button_text;
$title.after(button);
},
/**
* Generate a random coupon code
*/
generate_coupon_code: function( e ) {
e.preventDefault();
var $coupon_code_field = $( '#title' ),
$coupon_code_label = $( '#title-prompt-text' ),
$result = '';
for ( var i = 0; i < woocommerce_admin_meta_boxes_coupon.char_length; i++ ) {
$result += woocommerce_admin_meta_boxes_coupon.characters.charAt(
Math.floor( Math.random() * woocommerce_admin_meta_boxes_coupon.characters.length )
);
}
$result = woocommerce_admin_meta_boxes_coupon.prefix + $result + woocommerce_admin_meta_boxes_coupon.suffix;
$coupon_code_field.trigger( 'focus' ).val( $result );
$coupon_code_label.addClass( 'screen-reader-text' );
}
};
/**
* Handles warning about coupons using password protection.
*/
const wc_coupon_password_warning = {
init: function() {
const $warning = $( '#wc-password-protected-coupon-warning' );
// Bail out early if necessary.
if ( 0 === $warning.length ) {
return;
}
const $visibility = $( 'input[name="visibility"]' ),
$password_visibility = $( '#visibility-radio-password' ),
$password_label = $( 'label[for="visibility-radio-password"]' );
// For coupons without password, prevent setting it.
if ( ! $password_visibility.is( ':checked' ) ) {
$password_visibility.prop( 'disabled', true );
$password_label.css( 'text-decoration', 'line-through' );
return;
}
$visibility.on(
'change',
function() {
$warning.toggleClass( 'hidden', ! $password_visibility.is( ':checked' ) );
}
);
}
};
wc_meta_boxes_coupon_actions.init();
wc_coupon_password_warning.init();
});