PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, May 16, 2022

[FIXED] How to access wooCommerce config for cuustom WP Query

 May 16, 2022     php, woocommerce, wordpress     No comments   

Issue

Maybe this is already answered somewhere else, but I couldn't find it after researching for 5 days.

I've a custom WP Query that returns products for JavaScript AJAX client. My client wants to handle the "number of rows" and "columns" through wooCommerce config that is available through customization of shop page. enter image description hereenter image description here

Here's my basic implementation for custom WP Query:

function loadProducts(){
  // Access the number of rows and columns input here from customization page??
}
add_action("wp_ajax_loadprods","loadProducts");
add_action("wp_ajax_nopriv_loadprods","loadProducts")

Solution

From the ref: /wp-content/plugins/woocommerce/includes/wc-template-functions.php

function loadProducts(){
    $columns = get_option('woocommerce_catalog_columns', 4); 
    $rows = absint(get_option('woocommerce_catalog_rows', 4));
    
    echo json_encode(array('columns' => $columns, 'rows' => $rows));

    wp_die();
}
add_action("wp_ajax_loadprods","loadProducts");
add_action("wp_ajax_nopriv_loadprods","loadProducts")


Answered By - Barrie Dawson
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing