/**
* Изменение количества продуктов на странице
*
* @compatible WooCommerce 3.2.0 +
* @see https://github.com/woocommerce/woocommerce/blob/7701d4b57cb20dc89e25bb7bf2ff872d85f4c535/includes/class-wc-query.php#L412
*/
function loop_product_per_page( $per_page ) {
if ( ! empty( $_GET[ 'products-per-page' ] ) ) {
$per_page = (int) ( $_GET[ 'products-per-page' ] );
} else {
$per_page = 12;
}
return $per_page;
}
add_filter( 'loop_shop_per_page', 'loop_product_per_page', 9999 );
/**
* Define default terms for custom taxonomies in WordPress 3.0.1
*
* @author Michael Fields http://wordpress.mfields.org/
* @props John P. Bloch http://www.johnpbloch.com/
* @props Evan Mulins https://circlecube.com/circlecube/
*
* @since 2010-09-13
* @alter 2013-01-31
*
* @license GPLv2
*/
function mfields_set_default_object_terms( $post_id, $post ) {
if ( 'publish' === $post->post_status && $post->post_type === 'your_custom_post_type' ) {
$defaults = array(
'your_taxonomy_id' => array( 'your_term_slug' )
);
$taxonomies = get_object_taxonomies( $post->post_type );
foreach ( (array) $taxonomies as $taxonomy ) {
$terms = wp_get_post_terms( $post_id, $taxonomy );
if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) {
wp_set_object_terms( $post_id, $defaults[$taxonomy], $taxonomy );
}
}
}
}
add_action( 'save_post', 'mfields_set_default_object_terms', 100, 2 );
url:myajax.url?action=myfilter
data:{ qqq : 123,action: 'myfilter' },
var $data = {
action: 'myfilter',
qqq :123 ,
security: myajax.security,
}
$.post(myajax.ajaxurl, $data, function ($response) {
if ($response.success) {
console.info('Ответ от сервера', $response);
} else {
// обработка ошибок
}
});
add_action( 'wp_ajax_myfilter', 'my_filter_function' );
add_action( 'wp_ajax_nopriv_myfilter', 'my_filter_function' );
function my_filter_function() {
$check = check_ajax_referer( 'special-string', 'security' );
if ( empty( $check ) ) {
$error_code = 1;
}
if ( empty( $_POST[ 'qqq' ] ) ) {
$error_code = 2;
}
if ( ! empty( $error_code ) ) {
wp_send_json_error( [ 'error' => $error_code ] );
}
$str = esc_html( $_POST[ 'qqq' ] );
wp_send_json_success( [ 'str' => $str ] );
}
$vals = get_the_field( 'size' );
$vals_args = explode( ',', preg_replace( '/\s+/', '', $vals ) );
if ( !empty( $vals_args ) ) {
$options = '';
foreach ( $vals_args as $one_val ) {
$options .= sprintf( '<option value="%1$s">%1$s</option>', $one_val );
}
printf( '<select name="blablabla">%s</select>', $options );
}
function assign_pmpro_level_to_role($user_id, $role)
{
global $current_user;
//checks if the user doesn't have a membership level yet
if(!$current_user->user_id) {
//we found a role related to pmpro level
if($role == "customer")
{
pmpro_changeMembershipLevel(6, $user_id); //gives default customers the level 20 free registration membership
}
}
}
add_action('add_user_role', 'assign_pmpro_level_to_role', 10, 2);
$query = new WP_Query( [
'post_type' => 'fitnes_programs',
'posts_per_page' => (int)$count,
'tax_query' => [
[
'taxonomy' => 'fitnes_program',
'field' => 'id',
'terms' => [38]
]
]
] );