WP SITES
Forum Replies Created
-
Forum: Plugins
In reply to: [WooCommerce] Woocommerce deactivated and site crashedOne thing i know and thats Stripe and PayPal are harsh on eCommerce sites selling peptides.
Forum: Plugins
In reply to: [WooCommerce] Product category count wrongYou can add a custom column like this which includes products based on all statuses.
add_filter('manage_edit-product_cat_columns', 'custom_product_cat_columns');
function custom_product_cat_columns($columns) {
$columns['custom_count'] = __('All', 'woocommerce');
unset($columns['count']); // Remove default count column
return $columns;
}
add_filter('manage_product_cat_custom_column', 'custom_product_cat_column_content', 10, 3);
function custom_product_cat_column_content($content, $column, $term_id) {
if ($column === 'custom_count') {
$statuses = ['publish', 'draft', 'pending'];
$count = 0;
foreach ($statuses as $status) {
$query = new WP_Query([
'post_type' => 'product',
'post_status' => $status,
'tax_query' => [
[
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $term_id,
]
],
'fields' => 'ids',
'posts_per_page' => -1,
]);
$count += $query->found_posts;
}
// Link to filtered products by term ID
$term = get_term($term_id, 'product_cat');
$url = admin_url('edit.php?post_type=product&product_cat=' . $term->slug);
$content = '<a href="' . esc_url($url) . '">' . intval($count) . '</a>';
}
return $content;
}Forum: Plugins
In reply to: [WooCommerce] Product Categories List widget > Show only main categoriesadd_filter( 'woocommerce_product_categories_widget_args', 'show_only_parent_product_categories' );
function show_only_parent_product_categories( $args ) {
$args['parent'] = 0; // Show only top-level categories
return $args;
}See line 294 in wp-content/plugins/woocommerce/includes/widgets/class-wc-widget-product-categories.php
Tested and works.
You can add the code to the end of your child themes functions file or custom code snippets plugin.
FYI The widget name is Product Categories not Product Categories List Widget.
Forum: Developing with WordPress
In reply to: Query recent posts$category_ids = array(4, 7, 10); // Replace with your desired category IDs
foreach ( $category_ids as $cat_id ) {
$args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'DESC',
'cat' => $cat_id,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '<h3>Category: ' . get_cat_name( $cat_id ) . '</h3>';
echo '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
}
wp_reset_postdata();
}
}Forum: Plugins
In reply to: [WooCommerce] Cannot Insert Additional Information BlockThanks for your help with this shahzeen. Please mark as resolved even though i used code to make the field display. I’ll work out what the problem is at another time.
Forum: Plugins
In reply to: [WooCommerce] Cannot Insert Additional Information BlockIt shows but nothing happens when i click to insert. I had to use code to display it.
Its a bug.
I tested on 3 different sites using different themes and only WC active. TT4 and TT5
Would strongly advise against using page builders especially when using block themes.
Forum: Plugins
In reply to: [WooCommerce] Price displayed wrong on product pageTry this in functions.php and see what it gets.
add_action('wp_footer', 'dump_full_pricing_for_current_product');
function dump_full_pricing_for_current_product() {
if ( ! is_product() || ! current_user_can('administrator') ) return;
global $product, $woocommerce;
if ( $product && $product->is_type( 'variable' ) ) {
$variations = $product->get_available_variations();
echo '<pre>';
foreach ( $variations as $variation_data ) {
$variation = wc_get_product( $variation_data['variation_id'] );
$price_excl_tax = wc_get_price_excluding_tax( $variation );
$price_incl_tax = wc_get_price_including_tax( $variation );
// Simulated shipping cost placeholder (actual shipping can't be calculated without full cart + address)
$shipping_cost = 'Depends on shipping method & address';
// Simulated fees placeholder (fees are usually added via custom plugins or in cart context)
$fees = 'Depends on cart-level conditions';
$data = [
'variation_id' => $variation->get_id(),
'attributes' => $variation->get_attributes(),
'regular_price' => $variation->get_regular_price(),
'sale_price' => $variation->get_sale_price(),
'price' => $variation->get_price(),
'price_excl_tax' => wc_price( $price_excl_tax ),
'price_incl_tax' => wc_price( $price_incl_tax ),
'simulated_shipping' => $shipping_cost,
'simulated_fees' => $fees,
];
var_dump( $data );
}
echo '</pre>';
}
}Forum: Plugins
In reply to: [Query Loop Load More] Error on ActivationI ended up fixing it myself in my own plugin but thanks anyway.
Forum: Themes and Templates
In reply to: [Twenty Twenty-Five] Add a PHPYou could create a shortcode :
function apple_music_shortcode() {
ob_start();
the_field('apple_music_embed');
return ob_get_clean();
}
add_shortcode('apple_music', 'apple_music_shortcode');Forum: Themes and Templates
In reply to: [Twenty Twenty-Four] Leave a Comment (instead of leave a Reply)?Use a child theme https://ww.wp.xz.cn/plugins/create-block-theme/
Not fixed.
Forum: Plugins
In reply to: [WooCommerce] selling 2nd hand productsThere’s a cost of goods extension for this also https://woocommerce.com/document/cost-of-goods-sold/
Forum: Plugins
In reply to: [WooCommerce] selling 2nd hand productsAdd some code to your child themes functions file for the products purchase price.
add_action( 'woocommerce_product_options_general_product_data', 'add_purchase_price_field' );
function add_purchase_price_field() {
woocommerce_wp_text_input( array(
'id' => '_purchase_price',
'label' => __( 'Purchase Price', 'woocommerce' ),
'description' => __( 'Enter the purchase price of the product.', 'woocommerce' ),
'desc_tip' => true,
'type' => 'number',
'custom_attributes' => array(
'step' => '0.01',
'min' => '0'
),
));
}
add_action( 'woocommerce_admin_process_product_object', 'save_purchase_price_field' );
function save_purchase_price_field( $product ) {
if ( isset( $_POST['_purchase_price'] ) ) {
$product->update_meta_data( '_purchase_price', sanitize_text_field( $_POST['_purchase_price'] ) );
}
}
