Created
December 5, 2024 15:37
-
-
Save emre-edu-tech/2aa85bf161e3aae5ce4727cd59bbe32e to your computer and use it in GitHub Desktop.
This shortcode creates a custom woocommerce order type by an acf field called custom_product_popularity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// creating custom woocommerce order by an acf field called custom_product_popularity | |
function leoshop_add_new_postmeta_orderby( $sortby ) { | |
$sortby['custom_popularity'] = __( 'Sortieren nach benutzerdefinierten', 'hello-theme-child'); | |
return $sortby; | |
} | |
add_filter( 'woocommerce_default_catalog_orderby_options', 'leoshop_add_new_postmeta_orderby' ); | |
add_filter( 'woocommerce_catalog_orderby', 'leoshop_add_new_postmeta_orderby' ); | |
function leoshop_add_postmeta_ordering_args( $sort_args ) { | |
$cw_orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : | |
apply_filters( 'woocommerce_default_catalog_orderby', get_option('woocommerce_default_catalog_orderby')); | |
switch($cw_orderby_value) { | |
case 'custom_popularity': | |
$sort_args['orderby'] = 'meta_value_num'; | |
$sort_args['order'] = 'ASC'; | |
$sort_args['meta_key'] = 'custom_product_popularity'; | |
break; | |
} | |
return $sort_args; | |
} | |
add_filter('woocommerce_get_catalog_ordering_args', 'leoshop_add_postmeta_ordering_args'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment