我自己的Wordpress 笔记收集

  1. woocommerce Class WC_Cart
  2. Get the number of items in cart in wordpress using woocommerce 獲取woocommerce 購物車商品的數量
  3. WHY IS WOOCOMMERCE SO SLOW – HERE IS HOW TO FIX IT! 解決網站慢的問題呀
  4. woocommerce - Get Cart Total as number 列出了 WC()->cart的一些方法的結果

  • woocommerce mycred 日志在 woocommerce中分页解决

因为 wordpress 的 Permalink Settings 设定为 Post name

查考 WooCommerce Wallet – credit, cashback, refund system 插件,参考这个插件的结构,在woocommerce中添加了 endpoint,主要的功能是显示 mycred 的 会员积分余额和会员积分日志,最大的问题是 mycard_history 这个短代码中,分页的链接显示的 /my-account/[endpoint]/?page=3,点击这个链接,会跳回 /my-account/3页面,分页就处理不到。

当查看了 http://codex.mycred.me/classes/mycred_query_log/ 中获取页码有

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* Get Page Number
* @since 1.4
* @version 1.0.3
*/
public function get_pagenum() {

global $wp;

$page_key = ( isset( $this->args['page_arg'] ) && $this->args['page_arg'] !== NULL && $this->args['page_arg'] != '' ) ? $this->args['page_arg'] : 'page';
if ( isset( $wp->query_vars[ $page_key ] ) && $wp->query_vars[ $page_key ] != '' )
$pagenum = absint( $wp->query_vars[ $page_key ] );

elseif ( isset( $_REQUEST[ $page_key ] ) )
$pagenum = absint( $_REQUEST[ $page_key ] );

elseif ( isset( $_REQUEST[ $page_key ] ) )
$pagenum = absint( $_REQUEST[ $page_key ] );

else return 1;

return max( 1, $pagenum );

}

$this->args['page_arg'] 可以通过 http://codex.mycred.me/filters/mycred_query_log_args/mycred_query_log_args filter 覆盖 page_arg的参数名称,改为 定义的 [endpoint] 名称之后,分页就可以了

如:

1
2
3
4
5
function custom_mycred_transactions_args($args){
$args['page_arg'] = '[endpoint]';
return $args;
}
add_filter('mycred_query_log_args','custom_mycred_transactions_args'));


  • wordpress 打开媒体库弹窗
Reference
  1. How to include the WordPress media selector in your plugin 弹出媒体库和选择一个文件
  2. Show only images and videos in a wp.media window 只显示指定类型的文件
  3. ericandrewlewis/wp-media-javascript-guide 文档
  4. How to Create a Custom WordPress Post Type With Image Uploads

  • woocommerce 注册默认角色
Reference
  1. Assign another role instead of Customer used by WooCommerce