Forked from wpmudev-sls/wpmudev-sc-fix-quick-edit-woo-produtcs.php
Created
June 4, 2022 15:05
-
-
Save glaubersilva/f034ffee3e2fd00f16e21f547bbb6d94 to your computer and use it in GitHub Desktop.
[SmartCrawl] Fix Quick Edit For WooCommerce Products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [SmartCrawl] Fix Quick Edit For WooCommerce Products | |
* Plugin URI: https://wpmudev.com/ | |
* Description: The "quick edit" option on the admin area currently does not load the SEO fields for WooCommerce products, this plugin solves this problem. | |
* Author: Glauber Silva @ WPMUDEV | |
* Author URI: https://wpmudev.com/ | |
* Task: SLS-2727 | |
* License: GPLv2 or later | |
* | |
* @package WPMUDEV_SmartCrawl_Fix_Quick_Edit_For_WooCommerce_Products | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
add_action( 'admin_enqueue_scripts', function(){ | |
if ( is_admin() && class_exists( 'WooCommerce' ) && 'product' == get_post_type() && ! is_single() ) { | |
ob_start(); | |
?> | |
<script type="text/javascript"> | |
( ( $ ) => { | |
$( document ).ready( function() { | |
function populate_quick_edit_fields() { | |
var id = inlineEditPost.getId(this), | |
loading = Wds.l10n('post_list', 'loading'), | |
$quick_edit_fields = $(".smartcrawl_title:visible, .smartcrawl_metadesc:visible, .smartcrawl_focus:visible") | |
; | |
if (!$quick_edit_fields.length) { | |
return; | |
} | |
setTimeout(function () { | |
$quick_edit_fields.attr("placeholder", loading); | |
}); // Just move off stack | |
$.post(ajaxurl, { | |
"action": "wds_get_meta_fields", | |
"id": id, | |
"_wds_nonce": Wds.get('post_list', 'nonce') | |
}, function (data) { | |
$quick_edit_fields.attr("placeholder", ""); | |
if (!data) { | |
return false; | |
} | |
if ("title" in data && data.title) { | |
$(".smartcrawl_title:visible") | |
.val(data.title) | |
; | |
} | |
if ("description" in data && data.description) { | |
$(".smartcrawl_metadesc:visible") | |
.val(data.description) | |
; | |
} | |
if ("focus" in data && data.focus) { | |
$(".smartcrawl_focus:visible") | |
.val(data.focus) | |
; | |
} | |
}, "json"); | |
} | |
$(document) | |
.on('click', '.editinline', populate_quick_edit_fields) | |
; | |
} ); | |
} ) ( jQuery ); | |
</script> | |
<?php | |
$javascript = ob_get_clean(); | |
wp_add_inline_script( 'wds-admin-post-list-table', $javascript ); | |
} | |
}, PHP_INT_MAX); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment