I make my own plugin but I have a problem when I try to pass my function with the button. When I reload the page, my function passes but when I press the button, the function doesn't work. error Generate_coupon_woo undefined. I tried to do this for when a user tried to generate code with a click.
I make my own plugin but I have a problem when I try to pass my function with the button. When I reload the page, my function passes but when I press the button, the function doesn't work. error Generate_coupon_woo undefined. I tried to do this for when a user tried to generate code with a click.
<?php
/**
* Plugin Name: Demo remote post
* Description: connectd
* Version: 1.0.0
* Author: Digital Studio
*/
defined('ABSPATH') or die('Unauthorized Access !');
add_shortcode('nouveauShortcode', 'gererShortcode');
function gererShortcode(){
?>
<div class="wrap">
<h2>Digital Studio Plugin</h2>
<button class="btn btn-primary" type="but" id="submit">code Promo</button>
</div>
<script>
jQuery(document).ready(function($) {
$("#submit").on('click', Generate_coupon_woo);
});
</script>
<?php
}
function Generate_coupon_woo(){
$url='localhost:3306';
$coupon_code = substr( "abcdefghijklmnopqrstuvwxyz123456789", mt_rand(0, 50) , 1) .substr( md5( time() ), 1); // Code
$coupon_code = substr( $coupon_code, 0,10); // create 10 letters coupon
$amount = '15'; // Amount
$discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product // ici le type soit fixé sur le panier à la fin, soit en pourcentage sur le panier , soit fixé sur le produit, soit en pourcentage sur le produit
$coupon = array(
'post_title' => $coupon_code,
'post_content' => '€15 off coupon',
'post_excerpt' => '€15 off coupon',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'shop_coupon'
);
$username = "*******";
$password = "********";
$database = "******";
$mydb = new wpdb($username, $password, $database, $url);
$rows = $mydb->get_results("SELECT comment_author FROM VWfBb8z7_comments");
//$new_coupon_id = $mydb->wp_insert_post( $coupon );
$insert_test = $mydb->insert( 'VWfBb8z7_posts', $coupon );
update_post_meta( $insert_test, 'discount_type', $discount_type );
update_post_meta( $insert_test, 'coupon_amount', $amount );
update_post_meta( $insert_test, 'individual_use', 'yes' );
update_post_meta( $insert_test, 'product_ids', '' );
update_post_meta( $insert_test, 'exclude_product_ids', '' );
update_post_meta( $insert_test, 'usage_limit', '1' );
update_post_meta( $insert_test, 'expiry_date', '' );
update_post_meta( $insert_test, 'apply_before_tax', 'no' );
update_post_meta( $insert_test, 'free_shipping', 'no' );
update_post_meta( $insert_test, 'exclude_sale_items', 'no' );
update_post_meta( $insert_test, 'free_shipping', 'no' );
update_post_meta( $insert_test, 'product_categories', '' );
update_post_meta( $insert_test, 'exclude_product_categories', '' );
update_post_meta( $insert_test, 'minimum_amount', '' );
update_post_meta( $insert_test, 'customer_email', '' );
}
?>