【发布时间】:2017-09-04 19:17:04
【问题描述】:
我正在通过 wordpress 构建我的网站,我发现了一个很酷的插件,它显示了产品的总销售额和浏览量,我的问题是我需要使用 CSS 自定义字段,但我不知道如何添加类在 PHP 文件中,或者如果它是可能的。
我想添加类以自定义单个产品页面中的字段,因为如果我在没有特定类的情况下执行此操作,所有更改都会影响整个页面。这是代码。
<?php
/*
Plugin Name: Product Sold Count
Plugin URI: http:\\bhaskardhote.in
Description: This Plugin will used to show the total product sale count & and total view of product .Nice and easy way to know your sale of each product.
Version: 3.0.1
Author: Bhaskar Dhote
Author URI: http:\\bhaskardhote.in
*/
define( 'WP_WOOSOLD_URL', plugin_dir_url(__FILE__) );
define( 'WP_WOOSOLD_PATH', plugin_dir_path(__FILE__) );
define( 'WP_WOOSOLD_SLUG','woo_soldcount' );
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
global $wpdbb_content_dir;
if(!function_exists('wp_get_current_user')){
include(ABSPATH."wp-includes/pluggable.php") ; // Include pluggable.php for current user
}
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "View: 0";
}
return 'Views: '.$count;
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
add_action( 'woocommerce_single_product_summary', 'wc_product_sold_count', 11 );
function wc_product_sold_count() {
global $product;
setPostViews(get_the_ID());
$units_sold = get_post_meta( $product->id, 'total_sales', true );
echo '<p>'. sprintf( __( 'Total Sold: %s', 'woocommerce' ), $units_sold ).' '.getPostViews(get_the_ID());'</p>';
}
add_action('inti','wc_product_sold_count');
?>
【问题讨论】:
-
如果您只是询问如何设置输出样式 - ;
<p>标签 - 那么这非常容易。你试过什么?
标签: php css wordpress woocommerce