我需要在所有 WordPress 管理页面(后端)上添加 Livechat 小部件。
Livechat JavaScript 代码是这样的:
<!-- Start of LiveChat (www.livechatinc.com) code -->
<script type="text/javascript">
window.__lc = window.__lc || {};
window.__lc.license = 12345678;
(function() {
var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
})();
</script>
<noscript>
<a href="https://www.livechatinc.com/chat-with/10437202/" rel="nofollow">Chat with us</a>,
powered by <a href="https://www.livechatinc.com/?welcome" rel="noopener nofollow" target="_blank">LiveChat</a>
</noscript>
<!-- End of LiveChat code -->
Run Code Online (Sandbox Code Playgroud)
Livechat 有一个可以在前端页面上进行聊天的插件。我实际上想将此代码添加到 WordPress 后端的每个页面。 …
javascript wordpress wordpress-theming custom-wordpress-pages wordpress-admin
在 WooCommerce 中,我\xe2\x80\x99m 尝试在发布产品时触发操作,但它\xe2\x80\x99t 不起作用,这是我的代码:
\nadd_action( 'transition_post_status', 'my_call_back_function', 10, 3 ); \nfunction my_call_back_function( $new_status, $old_status, $post ) {\n if (\n 'product' !== $post->post_type ||\n 'publish' !== $new_status ||\n 'publish' === $old_status\n ) {\n return;\n }\n file_put_contents( 'file.txt', 'Product published', FILE_APPEND ); \n}\nRun Code Online (Sandbox Code Playgroud)\n这里我\xe2\x80\x99m 尝试创建一个文件并在其中放入一些文本。但正如我所说,该文件并未创建\xe2\x80\x99。
\nI\xe2\x80\x99m 使用 WordPress 5.8.1 和 Woocommerce 5.8.0。问题是什么以及如何解决?我们将非常感谢您的帮助。
\n提前致谢。
\nWoocommerce Paypal 付款插件在 Woocommerce 我的帐户页面上添加了“Paypal 付款”选项卡。如何完全删除此选项卡?
我已经尝试过从此处找到的代码片段修改的代码片段,但未能成功删除该选项卡。
add_filter ( 'woocommerce_account_menu_items', 'misha_remove_my_account_links' );
function misha_remove_my_account_links( $menu_links ){
unset( $menu_links['ppcp-paypal-payment-tokens'] );
return $menu_links;
}
Run Code Online (Sandbox Code Playgroud) 我想在变体名称后添加内容。
我找到这个钩子并看到它之前可以工作,但在我的测试中它不是:(
我想问,是否有另一种钩子/工作方法可以用来添加内容?
add_filter('woocommerce_attribute_label', 'custom_attribute_label', 10, 3);
function custom_attribute_label($label, $name, $product){
$taxonomy = 'pa_' . $name;
if ($taxonomy == 'pa_size')
$label .= '<div class="custom-label">' . __('MY TEXT', 'woocommerce') . '</div>';
return $label;
}
Run Code Online (Sandbox Code Playgroud)
php wordpress woocommerce hook-woocommerce woocommerce-theming
我已经从列表中隐藏了管理员用户并减去了用户数量,但是,用户列表中的管理员角色选项卡(用户>>所有用户)仍然显示,我想随意隐藏它。
这是我用来隐藏管理员的代码:
add_action('pre_user_query','site_pre_user_query');
function site_pre_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;
if ($username == 'admin') {
}
else {
global $wpdb;
$user_search->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.user_login != 'admin'",$user_search->query_where);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我用来减去用户数量的方法:
add_filter("views_users", "site_list_table_views");
function site_list_table_views($views){
$users = count_users();
$admins_num = $users['avail_roles']['administrator'] - 1;
$all_num = $users['total_users'] - 1;
$class_adm = ( strpos($views['administrator'], 'current') === false ) ? "" : "current";
$class_all = ( strpos($views['all'], 'current') === false ) ? "" : "current";
$views['administrator'] = '<a href="users.php?role=administrator" class="' …Run Code Online (Sandbox Code Playgroud) 我正在尝试从数据库获取具有值条件的自定义字段的产品。
自定义字段名为:"_filtered_product"。
我只想获得价值 = 1的产品
这是我写的 SQL 查询。
$view_low_filt_sql =
"LEFT JOIN $wpdb->postmeta manage ON (p.ID = manage.post_id AND manage.meta_key = '_manage_stock')
LEFT JOIN $wpdb->postmeta stock ON (p.ID = stock.post_id AND stock.meta_key = '_stock')
LEFT JOIN $wpdb->postmeta threshold ON (p.ID = threshold.post_id AND threshold.meta_key = '_low_inventory_number')
LEFT JOIN $wpdb->postmeta filtered ON (p.ID = filtered.post_id AND filtered.meta_key = '_filtered_product')
WHERE (p.post_type = 'product' OR p.post_type = 'product_variation')
AND (p.post_status = 'publish' OR p.post_status = 'private' OR p.post_status = …Run Code Online (Sandbox Code Playgroud) 我认为有一个非常简单的解决方案:
在 WooCommerce 中,我想将交货时间过滤器应用于单个产品,但前提是它是available/in stock. 在检查产品库存时,我遇到了错误。
function filter_woocommerce_germanized_delivery_time_html( $str_replace, $html ) {
global $product;
if( $product->is_in_stock() ) {
echo '<p class="wc-gzd-additional-info delivery-time-info">';
echo $str_replace;
echo '</p>';
echo '<p class="wc-gzd-additional-info"><a href="https://xyz.at/info/lieferzeiten/" target="_blank"><i class="fas fa-shipping-fast"></i> EU-Lieferzeiten</a></p></span>';
}
}
// add the filter
add_filter( 'woocommerce_germanized_delivery_time_html', 'filter_woocommerce_germanized_delivery_time_html', 10, 2 );
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
if($product->get_stock_quantity()>0)
Run Code Online (Sandbox Code Playgroud)
但类似的错误如:
“未捕获错误:在 null 上调用成员函数 is_in_stock() ..”
谢谢您的帮助!
问候,菲利克斯
当产品的长描述字段为空时,我想隐藏 WooCommerce 产品的“描述”标题。
我试过这个:
// Remove Empty Tabs
add_filter( 'woocommerce_product_tabs', 'yikes_woo_remove_empty_tabs', 20, 1 );
function yikes_woo_remove_empty_tabs( $tabs ) {
if ( ! empty( $tabs ) ) {
foreach ( $tabs as $title => $tab ) {
if ( empty( $tab['content'] ) && strtolower( $tab['title'] ) !== 'description' ) {
unset( $tabs[ $title ] );
}
}
}
return $tabs;
}
Run Code Online (Sandbox Code Playgroud)
但这并没有最终隐藏标题。该标题似乎不是实际的选项卡。
在渲染的源中看起来像这样:
<div class="product-description">
<h3 class="summary-description-title">Description</h3>
</div>
Run Code Online (Sandbox Code Playgroud) php wordpress woocommerce hook-woocommerce woocommerce-theming
在我的在线商店中,有两种标准运输方式 - 统一费率和免费送货。我添加了一个用于远程交付的插件。
因此,当客户在下订单时填写“城市”和“地址”字段时,必须添加新的送货方式。但在我选择统一费率或免费送货之前,新的送货是不可见的。
据我了解,我没有根据字段的填写自动更新运输方式。
我找到并编辑了这段代码:
add_action('wp_footer', 'woocommerce_custom_update_checkout', 50);
function woocommerce_custom_update_checkout() {
if (is_checkout()) {
?>
<script type="text/javascript">
jQuery( document ).ready(function( $ ) {
$('#billing_address_1').click(function(){
jQuery('body').trigger('update_checkout', { update_shipping_method: true });
});
});
</script>
<?php
}
}
Run Code Online (Sandbox Code Playgroud)
但直到我第二次单击填充字段时,交付方式才会更新。
我想用 AJAX 连接。如何编辑代码以便使用 AJAX 的结果立即可见,而无需再次单击填充的字段?
wordpress ×10
php ×9
woocommerce ×8
checkout ×1
fopen ×1
javascript ×1
mysql ×1
paypal ×1
sql ×1