plugin development – script seem not load with use wp_enqueue_script

Question

I’m pretty new in wordpress plugin dev

I want to load some js for a plugin with ajax request.

To do so I have created the following code (I have removed the non necessary code) :

all the file is in the same folder into plugins

script.js

console.log('loaded');
var ajax_url = wcdouchette_ajax_object.ajax_url;
console.log('ajax_url');

wc-douchette.php

class Wcdouchette {
    protected function __construct() {
        $this->init();
    }

    public function wcdouchette_includes() {
      // JavaScript
      wp_enqueue_script('wcdouchette-script-js', plugins_url( 'script.js', __FILE__ ));
      // Pass ajax_url to script.js
      wp_localize_script(
        'wcdouchette-script-js',
        'wcdouchette_ajax_object',
        array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
      );
    }

    private function init() {
      if (get_site_url() === 'https://wp-pp.test') $this->_isdev = true;
      add_action('wp_enqueue_scripts', array(&$this, 'wcdouchette_includes'));
      add_action('wp_ajax_wcdouchette_send_to_pmp', array(&$this, 'wcdouchette_send_to_pmp'));
      add_action('woocommerce_admin_order_actions_end', array(&$this, 'wcdouchette_btn_in_wcactions_column'));
      add_action('admin_menu', array(&$this, 'wcdouchette_options_page'));
      add_action('admin_init', array(&$this, 'wcdouchette_register_settings'));
    }
}

But i doesn’t see any console.log. Any idea ?

0
Hadock 1 month 2021-10-16T20:04:05-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse