vendredi 22 avril 2016

AddClass via plugin to WooCommerce product page

Alright, I have made a separate plugin to run a very simple jQuery code that should select divs that have classes with related-products and add print-no class to them like so:

jQuery.noConflict();
jQuery(document).ready(function($) {
    $("div.related products").addClass("print-no");
});

And then the following function on the plugins php file to make sure it's running:

function go_add_no2() {
    wp_enqueue_script( 'PrintCrop', plugins_url( '/PrintCrop.js' , dirname(__FILE__) ),array('jquery'),'',true );
}
add_action('wp_enqueue_scripts', 'go_add_no2');

My aim is to basically make sure that the div that outputs the related products would get the print-no class, and I was hoping to succeed this via jQuery, so I could use it further on other things of similar measure.

Now, I've tried all sort of different things, different filters, different add actions, such as woocommerce_after_single_product page, the related product args, out related products, and the like and I've tried to specify the script itself with some additional conditions, and the like, but I am just not sure what the issue is.

I went desperate enough to drop it to even add the true value to footer note to make sure it should run but, nothing seems to happen at all with or without it, I added the no-conflict too just incase and I've tried it with declaring the jQuery again, or without it, and so on…

On top, I've tried quite many things that I've managed to so far dig out with jQuery and Wordpress plugin and WooCommerce related keywords, but haven't had much use out of that either unfortunately.

So am I missing something very obvious, misunderstood something or how am I supposed to go at this?

Any help would be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire